I just what to declare the array of struct and take input and show output through functions. I have structure name as studentType and want to make a array of this structure. i make for loop to run 3 time but it just run 2 times for input and then show the result and in output function show my first input in second itration
#include<iostream>
#include<conio.h>
using namespace std;
void input();//prototype of input function
void print();
struct studentType{
char firstName[10];
char lastName[10];
char courseGrade;
double GPA;
};
int main()
{
studentType obj[3];
input();
print();
getch();
return 0;
}
void input() //taking input
{
studentType obj[3];
for(int i=0; i<3 ; i++)
{
cout<<"No."<<i<<" Enter Your First Name ?" ; cin.getline(obj[i].firstName,10); cout<<"\n";
cout<<"No."<<i<<" Enter Your last Name ?"; cin.getline(obj[i].lastName,10); cout<<"\n";
cout<<"No."<<i<<" Enter Your Course Grade ?"; cin>>obj[i].courseGrade; cout<<"\n";
cout<<"No."<<i<<" Enter Your GPA ?"; cin>>obj[i].GPA; cout<<"\n";
}
}
void print( )//showing results or printing
{
studentType obj[3]; //array obj its a struct type
for(int i=0; i<3 ; i++)
{
cout<<"No."<<i<<" Your First Name" <<obj[i].firstName<<endl;
cout<<"No."<<i<<"last Name " <<obj[i].lastName<<endl;
cout<<"No."<<i<<"Your Course Grade " <<obj[i].courseGrade<<endl;
cout<<"No."<<i<<"Your GPA " <<obj[i].GPA<<endl;
}
}