Create a program that will input 10 names of students, each student have 5 quizzes USING ARRAY
Sample output:
Enter name of student 1:
Enter quiz1:
Enter quiz2:
Enter quiz3:
Enter quiz4:
Enter quiz5:
The average is:
My program allows me to input the name and grades, but the average is SO FAR OFF, it even reaches a negative result when I put all of the grades into 10's and I don't understand why. :( If someone could help me I would greatly appreciate it. :)
You have a few issues the main thing is you are using c and c++ code and it seems better to pick one. Here is how I would write your program in c++ let me know if you have any questions.
#include <iostream>
#include <string>
usingnamespace std;
constint MAXSTUDENTS = 5;
int main()
{
struct {
float grade;
string studentName;
} student[MAXSTUDENTS];
for (int i = 0; i < MAXSTUDENTS; i++) {
cout << "please enter student " << i+1 << ". name: " ;
cin >> student[i].studentName;
cout << "please enter student " << i+1 << ". grade: " ;
cin >> student[i].grade;
}
int averageGrade = 0;
int totalStudentScore = 0;
for (int i = 0; i < MAXSTUDENTS; i++) {
totalStudentScore = totalStudentScore+ student[i].grade;
}
averageGrade = totalStudentScore/MAXSTUDENTS;
cout << "Average student grade is: " << averageGrade;
return 0;
}
EDIT
I realize my program works a bit differently but there should be enough information for you to fill in the blanks. Please feel free to ask any questions!
@Bdanielz Thanks for your reply! Though ti worked differently it's easily "editable". But I was just wondering, would this be possible to do without the data structures? :)