try this!!!
#include <string.h>
#include <iostream.h>
//you need this library to use getc() function
#include <stdio.h>
//this line goes at the top
#define MAX_STU 5
struct students {
char name[30];
int age;
char grade[2];
int iq;
};
struct students student_info(struct students data);
void print(struct students data);
void main(void) {
//you need to put struct before students
struct students student[MAX_STU];
int i;
//get the data
//all arrays start with zero in C
for (i=0; i<MAX_STU; ++i) {
student[i] = student_info(student[i]);
}
//print the data
//all arrays start with zero in C
for (i=0; i<MAX_STU; ++i) {
print(student[i]);
}
//this is just waiting for an input character,
//for more information, see getc() function
getc(stdin);
}
struct students student_info(struct students data) {
cout << "what is the students name: ";
//cin.getline (data.name, 30);
//this is almost the same as the previous line
cin >> data.name;
cout << "What is the students age: ";
cin >> data.age;
cout << "What is the students grade: ";
//cin.getline (data.grade, 2);
//this is almost the same as the previous line
cin >> data.grade;
cout << "What is the students IQ: ";
cin >> data.iq;
//this goes to a new line
cout << endl;
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;
}
Advice: next time you buy a new book, check it out in order to see if it's really good!
'Cause this example was really bad!
Regards,
------------------------
Abel Conde
[email protected]