In your while loop, you're telling it to loop five times and keeping track with variable count. Once you first enter the while loop, you're immediately incrementing it with the stament count++. Even if you're using this with a cout as output, it still increments it. What does this mean? It means that once it enter, it equals 1, and your statement of
if (count == 0) {
max = num;
min = num;
}
will never run. All you have to do is take the "++" from the "count" variable. You then increment this variable before another loop begins. Like this:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void) {
double num, sum = 0, avg=0, max=0, min=0;
int count = 0; // loop counter variable
while (count < 5) {
cout <<"Enter number " << count << ":";
cin >> num;
sum = sum + num;
if (count == 0) {
max = num;
min = num;
}
if (num > max) {
max = num;
}
if (num < min) {
min = num;
}
count++;
}
cout <<"The number of values entered is " << count << endl;
cout <<"The sum of values entered is " << sum << endl;
avg = sum / count;
cout <<"The average of values entered is " << avg << endl;
cout <<"The maximum value entered is " << max << endl;
cout <<"The minimum of value entered is " << min << endl;
return 0;
}
Also, don't forget to initialize your variables always. In this case, you'd want to set them to zero, as I did.
samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18