Right now, I'm trying to write a program that simply lets the user enter in numbers, which are then stored in a file. My problem stems from the fact that this is my first instance in using a sentinel value to allow the user to enter in information as long as they wish. I just need to number the user's inputs on the screen, but I can't seem to figure out how, since the program doesn't actually use a loop to enter in my more values. Here is my code thus far:
The variable "number" is what I'm using to label each input. When I had loops in the past, I could just insertCode:#include<iostream.h> #include<iomanip.h> #include<fstream.h> const int SENTINEL = 1337; int main() { int data; int number; ofstream out_file; cout << "This program is designed to record up to 50 scores between the values of 0 and"; cout << " 100. The scores will then be stored in another file. Please enter all of"; cout << " the needed scores and type -1337 to end the program and store the values."; cout << endl << endl; number = 1; out_file.open("stat_data"); cout << "Enter an integer (1337 to end input):\n"; cout << number << ". "; cin >> data; while ( data < 1 || data > 1000) { cout << "\nThe number entered was not within the parameters. \n\nPlease try again:\n"; cin >> data; } while (data != SENTINEL) { out_file << data << " "; cout << "Enter an integer (1337 to end input): "; cin >> data; } out_file.close(); return 0; }
but not now. Thanks for any help.Code:number = number++;