Hi, I'm having trouble understanding how they found the mean of the integers as a double.
The question is as follows:
Given a list of N integers, find its mean (as a double), maximum value, minimum value, and range. Your program will first ask for N, the number of integers in the list, which the user will input. Then the user will input N more numbers.
#include <iostream>
usingnamespace std;
int main()
{
int N;
cout << "Enter N: ";
cin >> N;
int acc = 0;
cout<<"Now enter each value and click 'Enter' after each one \n";
cin >> acc;
int minVal = acc;
int maxVal = acc;
for (int i = 1; i < N; ++i)
{
int a;
cin>>a;
acc+=a;
if(a<minVal)
{minVal=a;}
if(a>maxVal)
{maxVal=a;}
}
cout<<"Mean: "<<(double)acc/N<<"\n";
cout<<"Max: "<<maxVal<<"\n";
cout<<"Min: "<<minVal<<"\n";
cout<<"Range: "<<(maxVal-minVal)<<"\n";
return 0;
}
What I don't understand is line 27, where they found the mean by using "(double)acc/N". Isn't acc just the very first value entered and not the sum of all the integers? Any help would be appreciated.