help witn C++ and simple code
I need some help if someone wouldnt mind pointing me in the right direction.
I am trying to see if I can make a simple yes / no answer without having to use a switch and pointing to another function.
Here is my code:
void BLAH(~~~~~~){
int location = int();
int Part;
int choose;
choose = toupper(choose);
cout << "Add an item to the database Y/N?\n";
cin >> choose;}
So the user can hit y to go on with the rest of the program and n to exit back to the main menu.
if user enters Y the program goes on to prompt for a search for an item in the database.
I hope that is easy to understand and any help would be greatly appreciated.
Thanks,
M
[760 byte] By [
mnkdrt] at [2007-11-19 16:00:39]

# 1 Re: help witn C++ and simple code
Question is not clear.
Presuming that you require a y/n situation without switch
(choose=='y')? dosomthing(); : dosomethingelse();
this may help you.
regards
# 3 Re: help witn C++ and simple code
Question is not clear.
Presuming that you require a y/n situation without switch
(choose=='y')? dosomthing(); : dosomethingelse();
this may help you.
regards
# 4 Re: help witn C++ and simple code
Won't that crash the program?When the questions start with "Won't...?"/"Will..?"/etc. you should try that yourself and then if something happens as you were worrying come up with a question starting with "How...?"/"Why...?"/etc. That will be more helpful to you than people just stating the answers and you mugging them up. Also, do keep in my to check both uppercase and lowercase 'Y'/'y' separated by a OR (||) condition. Regards.
# 5 Re: help witn C++ and simple code
When the questions start with "Won't...?"/"Will..?"/etc. you should try that yourself and then if something happens as you were worrying
Well, in my experience, I don't know about your compiler; but whenever I try to cin>> and someone enters a character -- the program goes into an endless loop.
# 6 Re: help witn C++ and simple code
Well, in my experience, I don't know about your compiler; but whenever I try to cin>> and someone enters a character -- the program goes into an endless loop.Well, then you need to have a break; statement following up some conditional check. You cin the character inside the loop and if the user entered 'Y' or 'y' it proceeds with the loop and if there is anything else the control passes to this "break;" statement. It will quit the loop. Did you see the link that I provided in the other thread of yours? This one - inserting variables into running program (http://www.dev-archive.com/forum/showthread.php?t=366538)? Regards.
# 7 Re: help witn C++ and simple code
Did you see the link that I provided in the other thread of yours?
This isn't my thread, but yes.