//Write a c++ program that will input double numbers for the user in a loop
// until the average of the numbers is less than 10. When the loop ends
// display the sum and the average of the numbers.
My try to solve the question failed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
usingnamespace std;
int main()
{
int a, b, sum=0, i;
double avg=10.0;
cout<<"Enter a number: ";
cin>>a>>b;
while (avg>=10.0)
{
sum = sum+a+b;
avg= sum/i;
i++;
}
cout<<"sum ="<<sum<<endl;
cout<<"avg = "<<avg;
return 0;
}
He/she explicitly explicitly says "in a loop", @Abdullah Samo.
However, it is just plausible @mim97 has mis-translated the problem. @mim97, do you mean
(1) You keep entering a "double" (i.e. ONE floating-point number) until the average of all entered so far is less than 10?
OR DO YOU MEAN
(2) You keep entering TWO numbers until the average OF THOSE TWO NUMBERS is less than 10?
Your current code slightly favours the former, but who knows.