This is the same subject as your previous posts, just keep the other Topic going. If you post something, it will be at the top of the list. The problem is that someone might reply, only to find that someone else has said exactly the same thing in the other topic. So this is ultimately a time waster.
The if/else if statement allows your program to branch into one of several possible paths. It performs a series of tests (usually relational) and branches when one of these tests is true. The switch statement is a similar mechanism. It, however, tests the value of an integer expression and then uses that value to determine which set of statements to branch to. Here is the format of the switch statement:
// The switch statement in this program tells the user something
// he or she already knows: what they just entered!
#include <iostream>
usingnamespace std;
int main()
{
char choice;
cout << "Enter A, B, or C: ";
cin >> choice;
switch (choice)
{
case'A': cout << "You entered A.\n";
break;
case'B': cout << "You entered B.\n";
break;
case'C': cout << "You entered C.\n";
break;
default: cout << "You did not enter A, B, or C!\n";
}
return 0;
}