Below is a function to a program I am writing. The main program and everything else is not included due to the size of it, so I know some functions there will not make sense.
For some unknown reason to me, the program goes into an infinite loop when it reaches "Boss does not have enough mana." Why is that? I assumed that the switch statement will receive a new parameter(x) when the program falls under the else statement. Thank you.
On line 52, take out the word int. What's happening is line 52 is defining a new variable called x within the scope of that else block, and it "covers up" the x you're using in the rest of the program. Same thing is happening in the else block of case 2:
On line 35 you are creating a whole new variable, named x, and setting it to 1. This whole new variable ceases to exist when the else block is finished.
The original x variable is untouched. This is called shadowing.
If you change line 35 to x = 1; so that you are not creating a whole new variable, then the x in question will be the original x and it will work how you expect.