Wednesday, August 26, 2009

c++ switch statement example

1:// This is a single line comment
2:// Demonstrates switch statement
3:// This switch example does not used with the break keyword.
4:#include
5:
6:int main()
7
8:int number;
9:"Enter a number between 1 and 5:
10:
11:switch (number)
12:
13:case 0: "Too small, sorry!";
14:break;
15:case 5:
16:case 4: "Nice Pick!\n"; // fall through
17:case 3: "Excellent!\n"; // fall through
18:case 2: "Masterful!\n"; // fall through
19:case 1: "Incredible!\n"
20:
21:default: "Too large!\n";
22:break;
23:
24:cout "\n\n";
25:return 0

No comments: