TheGreatEscape
Active Member
- Joined
- Feb 4, 2011
- Sythe Gold
- 0
- Messages
- 147
Code:
#include <iostream>
using namespace std;
int main()
{
float count, rollingtotal, number, average;
count = -1;
rollingtotal = 0;
while (number != 00) {
cout << "Please input a number. Type '00' to exit: ";
cin >> number;
rollingtotal = (rollingtotal + number);
count++;
}
if (number == 00) {
average = (rollingtotal / count);
cout << "The Average of the numbers you entered are: ";
cout << average;
cout << " Total numbers entered: ";
cout << count;
} else {
cout << "Error";
}
}
2 problems that i have encountered.
1. If a person types '0' the loop will break. How do i make '00' not equal '0'. I know 00 is 0, but is there a way to stop that?
2. My count was always 1 above what it should be, the only way i found to fix this was to delcare count as -1. Is there a better way to fox this problem?
3. How would you write this programe? Since im guessing this could be omptimised alot.
Thanks


