New to programming here and doing a project for class.
Is it possible to get an answer from a loop statement and cout it?
I'm creating a grade book program that gets the average test score of the students. The question obtaining the average score is a loop, is there a way to get the average answer from the loop and use it in a cout statement?
I guess what i am asking is what is the variable that i use for the cout statement to get that average test score since it is looped?
Student 1 average is ****
Student 2 average is ****
Not sure if i am wording this correctly. Any assistance would be greatly appreciated
cout << "What is the teachers name: ";
getline(cin, teacher_name);
cout << "What is the class designation: ";
getline(cin, class_desig);
cout << "How many students are in the the class? ";
cin >> numStudent;
cout << "How many test scores does each student have? ";
cin >> numTest;
for (int student = 1; student <= numStudent; student++)
{
total = 0;
for (int grade = 1; grade <= numTest; grade++)
{
double score;
cout << "Enter grade " << grade << " for ";
cout << "student " << student << ": ";
cin >> score;
total += score;
}
average = total / numTest;
cout << "The average score for the student " << student;
cout << " is " << average << "\n";
if (average >= A_Grade)
cout << "Grade: A \n";
elseif (average >= B_Grade)
cout << "Grade: B \n";
elseif (average >= C_Grade)
cout << "Grade: C \n";
elseif (average >= D_Grade)
cout << "Grade: D \n";
else
cout << "Grade: F \n";
What I am trying to do is after this code is to create a template
That says
Teacher Name
Class Name
Student 1 Average is ***
Student 2 Average is ***
Class Average is ***
I cant figure out how to type a cout and to display student 1 average?