Hi.
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.

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

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

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

post your code i cheak

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.