Write a program in C++ to add 3 numbers and find the average number.
1
Expert's answer
2012-11-28T08:51:34-0500
#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; }
Comments
Leave a comment