Hi all,
I am very new to programming and am currently learning C++.
At the moment I'm at the stage of structures and classes, so am writing
many programs oriented around this to help. I have written a simple
problem which I cannot get to run.
Usually I have no big problems as the compiler aids me in debugging,
however this program compiles and I am not up to the stage of using a
debugging tool like GDB yet.
My program seems to jump after asking the age and when complete gives
very strange outputs.
I can't paste an error report with this as there is no error, hopefully
somebody can show me where I'm going wrong.
Code as follows:
#include
#include
struct students student_info(struct students data);
void print(struct students data);
#define MAX_STU 5
struct students {
char name[30];
int age;
char grade[2];
int iq;
};
main() {
students student[MAX_STU];
int i;
//get the data
for (i=1; i<=MAX_STU; ++i) {
student[i] = student_info(student[i]);
}
//print the data
for (i=1; i<=MAX_STU; ++i) {
print(student[i]);
}
}
struct students student_info(struct students data) {
cout << "what is the students name: ";
cin.getline (data.name, 30);
cout << "What is the students age: ";
cin >> data.age;
cout << "What is the students grade: ";
cin.getline (data.name, 30);
cout << "What is the students IQ: ";
cin >> data.iq;
return (data);
}
void print(struct students data) {
cout << "Name: " << data.name << endl;
cout << "Age: " << data.age << endl;
cout << "Grade: " << data.grade << endl;
cout << "IQ: " << data.iq << endl << endl;
}
thanks
Gedi