+ 1
i need c++ program does EXAMPLE: If the user entered the #’s: 999, 90,78,82,and 999 the output would be AVERAGE = 250/3 = 83.3 AVERAGE WITH LOWEST DROPPED = 172/2 = 86.0 AVERAGE WHERE HIGHEST COUNTS TWICE =340/4 = 85.0 NOTE: Validate the input as being a plausible test score and require the user to reenter when not plausible.
7 odpowiedzi
+ 1
where does 250 come from ?
+ 1
You have given three examples in your question, do you want a single program to perform all three type of averages? Or separate programs for each example?
+ 1
How do you get 250, 172, 340 from 999, 90, 78, 82 & 999 ? Can you please explain?
this problem seems interesting :)
+ 1
okay.. I'm on it :) is it only for three variable or more ?
+ 1
Here's the code. Tell me if it's according to your requirement or not?
#include <iostream>
using namespace std;
int main()
{
double n1, n2, n3, sum;
cout << "Enter first number: ";
cin >> n1;
while (n1 > 100 || n1 < 0)
{
cout << "\nTest score can't be greater than 100. Please enter a valid number: ";
cin >> n1;
}
cout << "Enter second number: ";
cin >> n2;
while (n2 > 100 || n2 < 0)
{
cout << "\nTest score can't be greater than 100. Please enter a valid number: ";
cin >> n2;
}
cout << "Enter third number: ";
cin >> n3;
while (n3 > 100 || n3 < 0)
{
cout << "\nTest score can't be greater than 100. Please enter a valid number: ";
cin >> n3;
}
//normal average
sum = n1 + n2 + n3;
cout << "\n\nNormal average of three numbers is: " << (sum/3);
//average with lowest dropped
if(n1<=n2 && n1<=n3)
sum = n2 + n3;
if(n2<=n1 && n2<=n3)
sum = n1 + n3;
if(n3<=n1 && n3<=n2)
sum = n1 + n2;
cout << "\n\nAverage with lowest dropped is: " << (sum/2);
//average with highest counting twice
if(n1>=n2 && n1>=n3)
sum = 2*n1 + n2 + n3;
if(n2>=n1 && n2>=n3)
sum = n1 + 2*n2 + n3;
if(n3>=n1 && n3>=n2)
sum = n1 + n2 + 2*n3;
cout << "\n\nAverage with highest counting twice is: " << (sum/4) << endl;
return 0;
}
0
for the three averages
0
we would just calculator from 0 to 100 and it would ignore the other numbers