# 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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment