64 564
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #19629 in C++ for Peter

Question #19629
Write a program in C++ to add 3 numbers and find the average number.
Expert's answer

#include <iostream.h>

int main(void)
{

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
have"
<< endl << "finished entering numbers and want to compute
the"
<< endl << "average of the inputted numbers." ;

do {
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 ;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions