Not sure why the while loop is not working although I think I specified what input was previously in the code.
#include <iostream>
using namespace std;
int main()
{
do
{
cout<<"1. \tOpen File"<<endl;
cout<<"2. \tClose File"<<endl;
cout<<"3. \tExit"<<endl;
int input;
cin >> input;
cout<<"Select and option: "<<endl;
switch(input)
{
case 1:
cout<<"Opening File"<<endl;
break;
case 2:
cout<<"Closing File"<<endl;
break;
case 3:
cout<<"Exiting..."<<endl;
break;
default:
cout<<"Invalid Entry"<<endl;
}
}
while (input < 1 || input > 3);
return 0;
}
I expect the program to ask for my input and if a type a wrong input the program would repeat
input is localised in the loop body, so it cannot be used in the stopping conditional expression.
Declare it outside the loop, i.e. before do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With