run time error agn!!!!! ><

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
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
thank you... i have tried and it works ..... thank a lot!!!!
Last edited on
so, if i m using the following code for integers... does it work??
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.
Topic archived. No new replies allowed.