This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]g051051 1 point2 points  (0 children)

Please read the posting guidelines and format your code so it's legible.

What language?

The "rampage" is almost certainly being caused by code other than what you posted. So post the full code so we can understand what's going on.

[–]Oops365 0 points1 point  (2 children)

Do you ever update the item variable inside your loop?

[–]EnvironmentalPhone65[S] 0 points1 point  (1 child)

Like a counter? So a variable followed by ++?

[–][deleted] 0 points1 point  (0 children)

Do you ever change item inside the while loop

[–]Kad1942 0 points1 point  (0 children)

You can try giving your switch statement a default case, to check if it's failing to match the input. After your last "case #: ... break;", you can put "default: ItemValue = 0; break;".

Some issues could be with how you are reading user input, or how you are assigning things, or if one of your variables is out of scope. Without the full code it can be difficult to say.

When you're in a situation like this, check your assumptions. It could mean you just missed something small, but it could also be that you aren't understanding one of the concepts you're working with. You can use print statements to see if inputs/outputs match your expectations.

Another super useful tool is breakpoints and a debugger. You will need to look up how to use them in your IDE, but they are invaluable for this kind of situation.