Hi Everyone, so for my project I needed to make a loop and get a certain amount of grades from the user and average them. I have gotten that part down but the last part is to show how many of the entered grades, in my case six, have passed or failed and I can't get my head around how to do it. The only solution I know of how to usually show grades is through if/else but my professor wants us to get the number of students who failed or pass. EX. 4 students passed, 2 students failed. Any tips or corrections to resolve this would be greatly appreciated.
#include <iostream>
usingnamespace std;
int main()
{
int total, //sum of grades
gradeCounter, //number of grades entered
grade, //one grade
average; //average of entered grades
//initialize the loop
total = 0; //clear total
gradeCounter = 1; //prepare to loop
//Start a while loop to acquire the students six grades
while (gradeCounter <= 6)
{
cout << "Enter your six grades. " << endl; //prompt for input
cin >> grade;
total = total + grade; // add grade total
gradeCounter = gradeCounter + 1; //increment counter
}
//Output the average of the grades
average = total / 6;
cout << "The average is " << average << endl;
//Output the number of students who failed and passed
if (grade > 70){
cout << ""
}
system("pause");
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int total, //sum of grades
gradeCounter, //number of grades entered
grade, //one grade
average; //average of entered grades
int students_passed = 0; // Note: Initialize here
int students_failed = 0; // Note: Initialize here
//initialize the loop
total = 0; //clear total
gradeCounter = 1; //prepare to loop
//Start a while loop to acquire the students six grades
while (gradeCounter <= 6)
{
cout << "Enter your six grades. " << endl; //prompt for input
cin >> grade;
total = total + grade; // add grade total
gradeCounter = gradeCounter + 1; //increment counter
if (grade > 70) // Note
students_passed = students_passed + 1; // ++students_passed;
else
students_failed = students_failed + 1;
}
//Output the average of the grades
average = total / 6;
cout << "The average is " << average << endl;
//Output the number of students who failed and passed
cout << "students passed: " << students_passed << endl; // Note
cout << "students failed: " << students_failed << endl; // Note
system("pause");
return 0;
}