how do i get the redundant question of pressing a number to quit or continue using another number? i need it to print out where it has one question after the end of my program.
#include <iostream>
using namespace std;
int main()
{
int user;
int sentinal=0;
do
//beginning of the do statement
{
cout << "Please Enter A Number 1 Thru 9." << endl;
cin >> user;
while ((user<1)||(user>9))
//beginning of the while statement
{
if (((user<1)&&(user!=0))||(user>9))
{
cout << "Invalid Response. Please Enter A Number Between 1 Thru 9.";
cin >> user;
}
//end of the if statement
else if(user=0)
{
system("pause");
return 0;
}
//end of else if
}//end of the while statement
switch(user)
//beginning of the switch statement
{
case 1:
cout << "Roman Numeral For 1 Is: I"<<endl;
break;
case 2:
cout << " Roman Numeral For 2 Is: II"<<endl;
break;
case 3:
cout << "Roman Numeral For 3 Is: III"<<endl;
break;
case 4:
cout << "Roman Numeral For 4 Is: IV"<<endl;
break;
case 5:
cout << "Roman Numeral For 5 Is: V"<<endl;
break;
case 6:
cout << "Roman Numeral For 6 Is: VI"<<endl;
break;
case 7:
cout << "Roman Numeral For 7 Is: VII"<<endl;
break;
case 8:
cout << "Roman Numeral For 8 Is: VIII"<<endl;
break;
case 9:
cout << "Roman Numeral For 9 Is: IX"<<endl;
break;
}//end of the switch statement
cout << "Press '0' To Quit, Or Any Other Number To Continue.";
cin >> sentinal;
}while(sentinal !=0);
//end of the do while statement
system("pause");
return 0;
}
In the else if part of your if statement:
use the comparison/evaluation operator "==" instead of the assignment operator "=". The former compares 2 variables(which is what you want for an if satement), the latter sets the second variable to equal the first.
The while loop in there seems redundant:
Just use the If else statement without the surrounding while loop; you will get the same result.
if (((user<1)&&(user!=0))||(user>9))
{
cout << "Invalid Response. Please Enter A Number Between 1 Thru 9.";
cin >> user;
}
else if(user==0) //"==" not "="
{
system("pause");
return 0;
}