Im writing an application for my intro to programming class and the objective is to set up a simple program that prompts the user to enter a series of positive integer numbers between 50 and 100 (inclusive) using the keyboard. Your prompt should tell the user to enter a negative number to stop the input process.
As the user enters the numbers, you should keep track of the number of valid entries they have made (those that fall in the allowed range), and add up those numbers entries. You do not need to store more than the single entered number, the count, and the current total you are calculating.
Once the user completes the data entry, produce output similar to this:
A total of 5 values were entered.
The sum of those numbers is 127
make a program that will have one variable and it will retrieve the users
Here is the code I wrote
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int loop = 1;
int value;
int times = 0;
cout << "Enter a negavtive number to quit" << endl;
cout << "\nPlease Enter Any Number Between 50 - 100" << endl;
while (loop == 1) {
cin >> value;
times++;
value += value;
if(value < 0) {
cout << "You entered " << times - 1 << " numbers" << endl;
cout << "Total: " << value << endl;
system("PUASE");
return EXIT_SUCCESS;
}// end if statement
} //end while loop
system("PAUSE");
return EXIT_SUCCESS;
}
Here is the output http://www.flickr.com/photos/62751645@N08/6286454476/
I think it may have something to do with the fact that I am using the int value to do two different tasks. How might I go about fixing this?
revision
thanks to all of you for the "fix" I add a new variable and it works like a charm, but now the math is not adding correctly http://www.flickr.com/photos/62751645@N08/6286526294/in/photostream
PAUSE
in your loop. – Alex Oct 27 '11 at 15:49