<<C++ HELP>>
trying to get the doe for the competition score with C++ coding, don't know if I have the while loop in the wrong place to read more athletes or one line of code is were another should be. the help will be greatly appreciated.
what is shown below is the input for the coding
Mirabella Jones's results:
7.50, 8.80, 7.00, 8.10, 8.00, 9.80, 9.30, 8.90, 9.10, 9.00
The highest score of 9.80 and the lowest score of 7.00 were
dropped
The average score is 8.59
Ruth Mendez's results:
9.80, 8.50, 6.00, 8.80, 8.60, 7.10, 7.80, 8.00, 7.20, 8.30
The highest score of 9.80 and the lowest score of 6.00 were dropped
The average score is 8.04
#include <iostream>
using namespace std;
int main()
{
float x = 1, y, average=0,sum=0;
// Smallest & largest
float min_v, max_v;
// Initialization state
bool initialized {false};
while (x < 11) {
cin >> y;
// Break out of the loop if
// input failed
if(!cin.good()) break;
// Initialization check, used
// to initialize min_v & max_v
// with the first value.
if(!initialized)
{
min_v = max_v = y;
initialized = true;
}
// Check whether y is less
// than min_v, if so,
// assign y to min_v
if(y < min_v)
min_v = y;
// Check whether y is larger
// than max_v, if so,
// assign y to max_v
if(y > max_v)
max_v = y;
sum=sum+y;
average=sum/10;
x++;
}
cout<<"\nSum ="<<sum;
cout<<"\nAverage = "<<average;
cout << "\nMin value: " << min_v << endl;
cout << "Max value: " << max_v;
return 0;
}
Comments
Leave a comment