Im currently working on a basic program that gives you 6 choices to choose from and you choose by inputting a number that corresponds with that selected choice. I've been running into more of a bug that chooses the first choice if the number you input is any number (between 2 and 6) except for 1, this isn't a problem if you choose the first choice but it is a problem if you want any other choice. Im sure you can understand what is going on in the code but for me im having a bit of trouble trying to figure out a way to get around this problem.
Heres an example:
Thanks it's working now ;)
The only reason i was using goto was because we are currently going over goto statements so i wanted to implement it in the program but the if and if else statements should do just fine :D
Or you can use a switch case which would probably work better in this situation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
switch (input)
{
case'1':
// Do stuff
break;
case'2':
// Do stuff for number 2
break;
default:
// Do stuff for every other input other then the ones specified
break;
}
Basically how it works is if the user enter's lets say 1 it will run whatever code is in the case'1':. And the default case is used for when someone enter a input that you have not specified like lets say they entered 3, since I don't have a case for 3 it will run the default case and whatever code is in that.
Alright i'll try out the switch statement in a little 'exercise' program tomorrow, haven't really covered much in class and i just feel like the learning is too slow so it's great to try out new things, i appreciate it.