line 46: error C2676: binary '[' : 'data' does not define this operator or a conversion to a type acceptable to the predefined operator
line 46: error C2228: left of '.score' must have class/struct/union
line 56: error C2676: binary '[' : 'data' does not define this operator or a conversion to a type acceptable to the predefined operator
line 56: error C2228: left of '.score' must have class/struct/union
line 58: warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
line 83: error C2676: binary '[' : 'data' does not define this operator or a conversion to a type acceptable to the predefined operator
line 83: error C2228: left of '.id' must have class/struct/union
line 84: error C2676: binary '[' : 'data' does not define this operator or a conversion to a type acceptable to the predefined operator
line 84: error C2228: left of '.score' must have class/struct/union
line 85: error C2676: binary '[' : 'data' does not define this operator or a conversion to a type acceptable to the predefined operator
line 85: error C2228: left of '.grade' must have class/struct/union
This is my program:
Expand|Select|Wrap|Line Numbers
- #include <string>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- struct data
- {
- int id;
- int score;
- char grade;
- };
- float getAverage (data& student);
- void readStuData (data& student);
- void assignGrades (data student);
- void reportResults (data student);
- int student[10];
- int main ()
- {
- data studentInfo;
- readStuData (studentInfo);
- getAverage (studentInfo);
- assignGrades (studentInfo);
- reportResults (studentInfo);
- return 0;
- }
- void readStuData (data& student)
- {
- int i;
- cout << "Please enter student ID: ";
- cin >> student.id;
- cout <<"Enter student score: ";
- cin >> student.score;
- //Read 10 students grade information
- for (i = 0; i < 10; i++)
- cin >> student[i].score;
- }
- float getAverage (data& student)
- {
- float avg;
- float sum = 0.0;
- int i;
- for (i = 0; i < 10; i++)
- sum = student[i].score + sum;
- avg = sum/10.0;
- return avg;
- }
- void assignGrades (data student)
- {
- float avg;
- if ((student.score <= avg + 10) && (student.score >= avg - 10))
- student.grade = 'S';
- else if (student.score > (avg + 10))
- student.grade = 'O';
- else if (student.score < (avg - 10))
- student.grade = 'U';
- }
- void reportResults (data student)
- {
- float avg;
- int i;
- cout << "The average is " << avg << endl;
- for (int i = 0; i < 10; i++)
- cout << setw(5) << "Student " << student[i].id << endl;
- cout << setw(10) << "Student's score is " << student[i].score << endl;
- cout << setw(15) << "Student's grade is " << student[i].grade << endl;
- }