// This program calculates the average of any number of numbers.
// Using the for structure
#include <iostream>
using namespace std;
#include <iostream>
int main()
{
int n, count;
float x, sum, avg;
sum = 0;
cout << "How many numbers? ";
cin >> n;
int size= n;
int array[size];
for (count=1; count<=n; count++){
cout << "Enter Number: ";
cin >> array[n];
sum = sum + array[n];
} //end for
cout << "The sum is " << sum << endl;
avg = sum / n;
cout << "The average is " << avg << endl;
system("pause");
return 0; //successful termination
}
John Johnson
“ First, solve the problem. Then, write the code. ”