Aug 24, 2013 at 9:36am UTC
if i accidentally enter "a" then it will be the run time error... how to solve??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
using namespace std;
int main ()
{
int option;
do
{
cout << string(34,' ' ) << "Nu1.Bakery" <<string(35,' ' ) << endl;
cout << "1.New Order" << endl;
cout << "2.Cakes Types" << endl;
cout << "3.Order Summary" << endl;
cout << "4.Exit" << endl;
cout << "Please choose the option :" ;
cin >> option;
} while (option <= 4 || option >= 1);
return 0;
}
Last edited on Aug 24, 2013 at 10:24am UTC
Aug 24, 2013 at 10:05am UTC
operator >> reads data delimited by white spaces. So if you enter as you said
michale jackson then operator >> will read only the first word. The second word will be read by the next operator >>. If you want to enter the whole line you should use function std::getline( std::cin, firstname ).
Last edited on Aug 24, 2013 at 10:06am UTC
Aug 24, 2013 at 10:12am UTC
thank you... i have tried and it works ..... thank a lot!!!!
Last edited on Aug 24, 2013 at 10:14am UTC
Aug 24, 2013 at 10:17am UTC
so, if i m using the following code for integers... does it work??
Aug 24, 2013 at 11:03am UTC
First of all this condition of the loop
} while (option <= 4 || option >= 1);
is invalid. Should be
} while (option <1 || option > 4);
And you should check whether the execution of operator >> was successful.