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 } }
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:"
}
}
}
+ 7
You need to elaborate on "this doesn't work". What errors are you getting?
0
thank you
0
this doesn't work
0
..\Playground\: In function 'int main()':
..\Playground\:23:8: error: expected ';' before '}' token
}
^