Answer to Question #19629 in C++ for Peter
Write a program in C++ to add 3 numbers and find the average number.
int count; // holds the count
float sum, number, avg;
sum = 0.0;
count = 0;
cout << endl << endl // Make some space
<< endl << "Enter a number. Enter a zero (0) when you
<< endl << "finished entering numbers and want to compute
<< endl << "average of the inputted numbers." ;
cout << endl << endl << "Data element #"
<< count + 1<< ": ";
cin >> number;
if (number != 0.)
sum = sum + number;
count = count + 1;
} while (number != 0.0);
averg = sum / (count-1);
cout << endl << "The average is: " << avg
<< endl << endl ;
No comments. Be first!