![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Noob C++ Question. within the Everything Windows forums, part of the General PC Forums category; I was wondering what the code would be for a number selection menu, such as: Spoiler for Example : 1. ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() QJ's Nice-guy :)
My Mood:
Join Date: Mar 2006
Real First Name: Randy Andy
Location: UK
Just Played: Nazi Zombies
Posts: 4,191
Trader Feedback: 0
|
I was wondering what the code would be for a number selection menu, such as:
Spoiler for Example:
Sorry for the noob question, I've literally only just started learning C++ about 3 days ago and I'm just learning the basics at the moment. Much obliged!
|
|
|
|
|
|
#2 |
![]() |
Well I only know very basic C++ in a command prompt window but I would get it to print the options, then ask for an input and then use an if to check the answer. My syntax might not be correct because I haven't used C++ alot bu here it goes:
Code:
string answer;
cout << "Please choose an option" << endl << " 1. Red" << endl << "2. Green" << endl << "3. Blue" << endl << "4. Yellow" << endl << "Choice:";
cin >> answer;
if (answer == 1)
cout << "You chose Red";
elseif (answer == 2)
cout << "You chose Green";
elseif (answer == 3)
cout << "You chose Blue";
elseif (answer == 4)
cout << "You chose Yellow";
else
cout << "Please enter a valid choice";
Hope that helps! Edit, if I remember correctly the program will close instantly after the user input number and it has checked it so you may need to get it to wait for another input. So like make it ask if the user wants to exit and if they press Y then do Code:
return 0;
__________________
[CENTER][IMG]http://img232.imageshack.us/img232/7619/gggggggzq2.png[/IMG][/CENTER][CENTER][B]PSP[/B]: Black (JP) 1.50 + White (UK) 1.50 | [B]PSN[/B]: FranzH - Feel free to add [/CENTER] [CENTER][SIZE=1]Currently Playing:[B] PC[/B]: WoW + GHIII | [B]PS3[250GB][/B]: TimeCrisis 4 + MGO Beta + COD4 [/SIZE][/CENTER] |
|
|
|
|
|
#4 |
![]() |
Tell me how it goes
__________________
[CENTER][IMG]http://img232.imageshack.us/img232/7619/gggggggzq2.png[/IMG][/CENTER][CENTER][B]PSP[/B]: Black (JP) 1.50 + White (UK) 1.50 | [B]PSN[/B]: FranzH - Feel free to add [/CENTER] [CENTER][SIZE=1]Currently Playing:[B] PC[/B]: WoW + GHIII | [B]PS3[250GB][/B]: TimeCrisis 4 + MGO Beta + COD4 [/SIZE][/CENTER] |
|
|
|
|
|
#5 |
|
No longer a community member.
|
Make sure you #include <string> in that example. However, I wouldn't suggest using a string, because that code won't work with just a string. Change the line that says "string answer" to "int answer".
Also, I would suggest doing a while loop around it, since it's a menu. Dunno, that's what it sounded like you wanted to do |
|
|
|
|
|
#6 |
![]() |
Oh yeah >.< I have no idea why I used string...
__________________
[CENTER][IMG]http://img232.imageshack.us/img232/7619/gggggggzq2.png[/IMG][/CENTER][CENTER][B]PSP[/B]: Black (JP) 1.50 + White (UK) 1.50 | [B]PSN[/B]: FranzH - Feel free to add [/CENTER] [CENTER][SIZE=1]Currently Playing:[B] PC[/B]: WoW + GHIII | [B]PS3[250GB][/B]: TimeCrisis 4 + MGO Beta + COD4 [/SIZE][/CENTER] |
|
|
|
|
|
#7 | |
![]() QJ's Nice-guy :)
My Mood:
Join Date: Mar 2006
Real First Name: Randy Andy
Location: UK
Just Played: Nazi Zombies
Posts: 4,191
Trader Feedback: 0
|
Quote:
OK, I got it all sorted except for a single error: Code:
error C2143: syntax error : missing ')' before 'constant' Error executing cl.exe. |
|
|
|
|
|
|
#8 |
![]() |
You need to put a ' ) ' somewhere.. look for the line number :l
__________________
[CENTER][IMG]http://img232.imageshack.us/img232/7619/gggggggzq2.png[/IMG][/CENTER][CENTER][B]PSP[/B]: Black (JP) 1.50 + White (UK) 1.50 | [B]PSN[/B]: FranzH - Feel free to add [/CENTER] [CENTER][SIZE=1]Currently Playing:[B] PC[/B]: WoW + GHIII | [B]PS3[250GB][/B]: TimeCrisis 4 + MGO Beta + COD4 [/SIZE][/CENTER] |
|
|
|
|
|
#11 |
![]() QJ's Nice-guy :)
My Mood:
Join Date: Mar 2006
Real First Name: Randy Andy
Location: UK
Just Played: Nazi Zombies
Posts: 4,191
Trader Feedback: 0
|
Actually, one more little question.
How can I get it to loop back to the user prompt after an option has already been chosen? Thanks |
|
|
|
![]() |
| Tags |
| noob , question |
| Thread Tools | |
|
|