This is a homework assignment but I am doing a little extra. Mainly because I like to call functions in main and keep it as clear as I can. With that being said, I am having an issue passing input from a struct from one function to another. Also the array is failing but when I did the same thing in initially when I first declared it it was fine, why?
Code:#include <iostream>
using namespace std;
void HW_step1and3();
void HW_step_4();
void print_HW4();
const char name_size = 20;
struct StudentRecord {
char Name[name_size];
int ID;
float GPA;
};
void HW_step1and3()
{
StudentRecord TESCStudent;
TESCStudent.Name[name_size]= {"SuperProgrammer"}; //When I used it in the struct itself it was fine. Now I get an error
TESCStudent.ID=1234;
TESCStudent.GPA=4.0;
for (size_t i=0; i<sizeof(TESCStudent.Name); i++) {
cout<< TESCStudent.Name[i];
}
cout<<"\n" <<TESCStudent.ID<<endl;
cout<< TESCStudent.GPA<<endl;
cout<<" "<<endl;
}
void HW_step_4()
{
StudentRecord TESCStudent;
cout<<"Please enter the Students Name:"<<endl;
cin>>TESCStudent.Name;
cout<<"Please Enter the Students ID Number:"<<endl;
cin>>TESCStudent.ID;
cout<<"Please Enter the students GPA"<<endl;
cin>>TESCStudent.GPA;
print_HW4(struct TESCStudent.name,struct TESCStudent.ID,struct TESCStudent.GPA);
}
void print_HW4(struct char, struct int, struct float) // this was a real reach, I have good feeling its wrong
{
//I'll print the above here
}
int main(int argc, const char * argv[])
{
HW_step1and3();
HW_step_4();
return 0;
}