I,ve got some very helpfull advice from various experts on here and have nearly finished my program but am having a problem with a do while loop. When i try to put a do while ( the input isn't numbers one to ten) loop on a certain part of my program it works fine when a number that isn't one to ten is put in but if you put in a letter (which should make that part repeat again) it just dies and the screen starts flickering. I have tried a few things but with no joy. My only other idea was to use letters a to j instead. Hopefully this would work because later on in the program i have another two do while loops working on the exact same principle but with letters and they work fine when either the wrong letter is input or a number is input.
The only problem i have is that i use a switch statment to return a statement and if i use letters for the choice at the beginning i will need to make the switch statement work with case a: case b: etc. and not case1: case 2: etc.
Is there any way you can set up a switch statement to work with lettters for each case? It is slightly annoying that i cant get the do while loop working at the beginning but it just doesn't like it when you put a letter in and not a number.
Any help would be great. Thankyou.

7 Years
Discussion Span

case statements must be constants. You can not use variables there

switch( some_variable )
case 'a':
  // blabla
case 'b':
   // blabla
case 'c': case 'd': case 'e':
   // this for all three characters
<etc. etc for each letter you want to support>

Edited by Ancient Dragon: n/a


What if the expression in switch contains 2 expressions....say like this
Switch (a,b)
What would be the input ?
Switch (a,a+1)
Here, what would be the i/p and o/p


one of the common mistakes of using switch that you use variables instead of constants i.e. use "case 'a' :"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.