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;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment