but i dont know how to use case structure.can you give me an example of it
I will not solve it for you here, you need to learn how to use the many C++ references you have available. I looked up switch-case statement on Google using this query: " switch case statement +"C++" " and I got many pages of hits, most of which give a clear definition and usage for the switch-case statement.
One of the references I found gives a good example:
http://www.fredosaurus.com/notes-cpp/statements/switch.html
The key to using a switch-case statement is the case values must be immutable (constants) and not variables. For example:
- int age, mary;
-
char can_vote = FALSE;
-
-
switch (age) {
-
case 16:
-
case 15:
-
break;
-
case mary: // illegal case conditional, cannot be a variable
-
can_vote = TRUE;
-
break;
-
case 'Q':
-
// the constant character Q was assigned to age
-
break;
-
default:
-
break;
-
} // end switch(age)
-
The other mistake often made is forgetting to use the break statement between cases. In the example above, if age contained the value 16, control flow would fall into the statement for the case of 15, there was no break after the case to seperate them.
If, after trying the examples easily found by searching for the switch-case reference you have specific questions, feel free to ask.