Project: to create a c++ program that will loop enter grades for each student un
ID: 3758653 • Letter: P
Question
Project: to create a c++ program that will loop enter grades for each student until a negative grade is entered. When a negative grade is entered you will print the statistics: - number of students - lowest and highest grade - average grade -num of students who passed and failed. My only problem is I cant get it to calculate how many students passed or failed. Here is my code below: #include #include using namespace std; void main() { float total; float grade; int gradecounter; float average; //average grade float highest; //highest grade float lowest; //lowest grade int pass = 0; int fail = 0; grade = 0.0; highest = grade; lowest = grade; total = 0.0; gradecounter = 0; cout << "Enter grades one at a time. When finished, enter a negative value to end. "; cout << "Enter first grade: "; cin >> grade; while ( grade != -1, grade >= 0.0) { total= total + grade; gradecounter++; if ( grade >= highest) highest = grade; cout << "Enter grade or -1 to end: "; cin >> grade; } if (gradecounter == 0) cout << "There are no statistics to report " << endl; else { average = total / gradecounter; while ( gradecounter >= 70) { if (grade == 1) pass = pass + 1; else fail = fail + 1; } cout << "There are " << gradecounter << " grades" << endl; cout << "The grades range from 0 to 100" << endl; cout << "The average is " << average << endl; cout << "Lowest grade was " << lowest << endl; cout << "Highest grade was " << highest << endl; cout << "Passed: " << pass << endl; cout << "Failed: " << fail << endl; system("pause"); } }
Explanation / Answer
Programm :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.