#i can't understand this Q

6 messages · Page 1 of 1 (latest)

crystal herald
#

#include <iostream>
#include <iomanip> // For std::setprecision
using namespace std;
int main() {
double total = 0.0;
int counter = 0;
double grade = 0.0;
cout << "Enter grade (-1 to end): ";
cin >> grade;
while (grade != -1) {
total += grade;
counter++;
cout << "Enter grade (-1 to end): ";
cin >> grade;
}
double average = total / counter; cout << "Class average = " << fixed
<< setprecision(4) << average << endl;
return 0;
}

=======================
Task 5.2: How might you improve the code to overcome any unacceptable behaviors in the
program .

Task 5.3: The user wants also to find the minimum and the maximum of all entered grades. How
might you modify the code to allow this new requirement?

Hint: assume the biggest number for the minimum variable and the smallest number for the
maximum variable with which you start.

rain auroraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

gilded hawk
gusty cipher
#

The unacceptable behavior is probably that it crashes when counter is 0. And that if you enter "lol" it goes into an infinite loop with no way to recover. There are probably other issues as well.

crystal herald
rain auroraBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity