| Ferrous Moon http://www.ferrousmoon.com:80/forums/ |
|
| Help with C++ Program http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1214 |
Page 1 of 1 |
| Author: | Darkknight512 [Mon Jan 28, 2008 9:35 pm ] |
| Post subject: | Help with C++ Program |
Right now I am trying to make a program that uses a switch/case but i need to have a goto back to the top. The problem is that the goto loop doesn't goto loop, i think its because it is in the switch/case, can someone help me resolve this, its important. (If the goto loop cant do it, suggest an alternative please) Code: void location()
{
int choice = 0;
int secondchoice = 0;
loop:
switch (choice)
case 0:
{
cout << "What would you like to do?";
cout << "1.Dosomthing";
cout << "2.Dosomthing else";
cin >> secondchoice;
switch (seconchoice)
case 1:{
//do something
goto loop;
break;
}
case 2:{
//do something else
goto loop;
break;
}
break;
}
}
Thanks, Darkknight512
|
|
| Author: | Lohi [Tue Jan 29, 2008 11:28 am ] |
| Post subject: | Re: Help with C++ Program |
secondchoice is typed wrongly in the second switch. With that corrected it works fine (with visual express 2005 atleast). You can do that also without gotos with continue: Code: void location()
{
int choice = 0;
int secondchoice = 0;
while(1){
switch (choice)
case 0:
{
cout << "What would you like to do?\n";
cout << "1.Dosomthing";
cout << "2.Dosomthing else";
cin >> secondchoice;
switch (secondchoice)
case 1:{
//do something
continue;
}
case 2:{
//do something else
continue;
}
}
}
}
|
|
| Author: | Darkknight512 [Tue Jan 29, 2008 4:28 pm ] |
| Post subject: | Re: Help with C++ Program |
Well I only quickly typed that out not to release my actual code but I'll try the continue;. Edit: I added the continue but it dosen't seem to go back to the while(1). Edit 2: Never mind it was an error else where in my code, (did a int choice = 0, instead of choice = 0) Thanks a lot it worked |
|
| Page 1 of 1 | All times are UTC-05:00 |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|