0

sentinel code to run and stop program

I need a sentinel or a program to add to my pay stub code. #include <iostream>; using namespace std; const int SENTINAL = 1; int main() { int input=0, cout << " Press 1 if you want to try agian, /n Press 2 if you're done!." << endl; cin >> input; while (input < 0 || input > 2) { cout << "that value is unacceptable.. try again:" cin >> input; } cout << "the value" << input << endl; if esle ( input ==1){ //stop program } if esle (input ==2){ //run program } }

27th Jun 2017, 6:34 AM
Reginald Wright
Reginald Wright  - avatar
5 Réponses
+ 7
// This, is sentinel controlled loop. #include <iostream> using namespace std; int main() { int input=1; while (input == 1) { // program runs input = 0; while (input < 1 || input > 2) { cout << "Input 1 if you want to try again." << endl; cout << "Input 2 if you're done!." << endl; cin >> input; if (input < 1 || input > 2) cout << "that value is unacceptable.. try again:" } } }
27th Jun 2017, 7:04 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
You need to elaborate on "this doesn't work". What errors are you getting?
28th Jun 2017, 1:43 AM
Hatsy Rei
Hatsy Rei - avatar
0
thank you
27th Jun 2017, 10:54 PM
Reginald Wright
Reginald Wright  - avatar
0
this doesn't work
27th Jun 2017, 11:49 PM
Reginald Wright
Reginald Wright  - avatar
0
..\Playground\: In function 'int main()': ..\Playground\:23:8: error: expected ';' before '}' token } ^
1st Jul 2017, 4:52 AM
Reginald Wright
Reginald Wright  - avatar