I am trying to create a program that allows the user to input 6 quiz grades for x number of students. X being up to 300 students. you also have to be able To compute the class average on a specific quiz, see the letter grade of a specific student, and compute the overall class average in the course.
this is what ive been able to do so far, however i am unsure as if i should make a function to calculate the average of the quizzez, and if i do how should i link the variable in the for loop that is number_of_students to the function.
#include<iostream>
#include<cmath>
usingnamespace std;
void menu();
float quiz_avg();
int main()
{
char choice;
char ans = 'N';
char y;
int number_of_students,x;
float grades[300][6];
char input;
do
{
menu();
cin>> input;
if (input == '1')
{
cout<<"Please give a value for number of students:"<<endl;
cin>> number_of_students;
for (int i = 0; i < number_of_students; i++)
{
for (int j = 0; j < 6; j++)
{
cout<< "grade of student "<< i+1 << " for quiz " << j+1 <<endl;
cin>> grades[i][j];
}
}
menu();
cin>> input;
if (input=='1')
cout<< "please restart the application to enter new scores"<<endl;
elseif (input!='1-4')
cout<< "invalid choice. only options 0-4 are allowed"<<endl;
elseif (input ==2)
{
cout<< "Give the number of the quiz ";
cin>> x;
}
}
elseif (input =='2')
cout<< "No scores inputed"<<endl;
elseif (input =='3')
cout<< "No scores inputed"<<endl;
elseif (input =='4')
cout<< "No scores inputed"<<endl;
elseif (input>'4')
cout<< "Wrong choice. Only options 1-4 are available."<< endl;
if (input=='0')
{
cout<<"are you sure you wish to exit? (Y/N)"<< endl;
cin>> ans;
}
elseif (input<'1')
cout<< "Wrong choice. Only options 1-4 are available."<< endl;
}
while (ans !='y'&& ans != 'Y');
system("pause");
return (0);
}
void menu()
{
cout<< "Student project Database"<< endl;
cout<<endl<<endl;
cout<< "Please choose an option"<<endl;
cout<<"1. To store the scores for a students quizzez"<< endl;
cout<<"2. To compute the class average on a specific quiz"<< endl;
cout<<"3. To see the letter grade of a specifit student" <<endl;
cout<<"4.To compute the overall lass average in the course"<< endl;
cout<<"Press 0. To quit"<<endl;
cout<<"Please make a choice;"<<endl;
}
An average would be the total points achieved by all students on a quiz divided by the number_of_students. You could make this a separate function. I might even split out some of your other processing into separate functions.
I'd probably validate that they don't enter a number greater than 300 for the number of students, to prevent the program from going out of bounds on the array.