Hi

I was trying to write a code to read n numbers and find total, min, max, average for those n numbers. There is clearly something wrong with the code which I have failed to understand. Please help me. I'm new to these loops.

Best regards

Jackson

Code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i, n;
float number, total=0, min=500, max=0, average;
cout << "How many numbers are there?: ";
cin >> n;
for (i=0; i<n; i+=1)
{
cout << "Enter the number: ";
cin >> n;
total = total + n;
if (n < min)
{
min = n;
}
if (n > max)
{
max = n;
}
}
cout << "Total is: " << total << endl;
cout << "Minimum is: " << min << endl;
cout << "Maximum is: " << max << endl;
cout << "Average is: " << total/n << endl;
system("pause");
}

**Output:**

Code:

How many numbers are there?: 9
Enter the number: 1
Total is: 1
Minimum is: 1
Maximum is: 1
Average is: 1
Press any key to continue . . .