#include <iostream>
#include <iosmanip>
#include <math.h>
usingnamespace std;
constint SIZE = 5;
constint LINE = 4;
//function prototypes
void getData(int arr[]);
void print(constint arr[]);
double findAverage (int arr[]);
void printAverage(double average);
int main()
{
int arr[SIZE];
double average;
getData(arr);
average = findAverage(arr);
print(arr);
printAverage(average);
cout <<endl;
system("PAUSE");
return 0;
}
// Prompt user to enter value and then assign value to array.
void getData(int arr[])
{
for (int i=0;i<SIZE;i++)
{
cout <<"Enter a value #"<< i+1<<endl<<" :";
cin>>arr[i];
}
}
// Calculate the average.
double findAverage (int arr[])
{
int sum = 0;
double average;
for (int i=0; i<SIZE;i++)
{
sum += arr[i];
average = static_cast<double>(sum)/SIZE;
}
return average;
}
// Print each element of the array by printing 4 element per line
void print(constint arr[])
{
int i;
int j;
cout <<"Array Element Are: "<<endl<<endl;
for (i=0, j=0; i<SIZE;i++,j++) // for-loop to print all element
{
if (j==LINE) // Print 4 element per line
{
j=0;
cout <<endl;
}
cout <<setw(3)<<arr [i]; // print element, space 3.
}
}
// Print average.
void printAverage(double average)
{
cout << " The average is : " <<average<<endl;
}
My error is on line 69. I don't see anything wrong with it.
If i take out setw(3), it doesnt get any error but for some reason it doesnt run. Any idea or suggestion? Possible i did something wrong there?
Thank you.
I usually use visual studio and it tell me right away if i type something wrong, but that not the case. hehe. I will have to be more careful next time and thank for the advice.