So I am new to C++ (obvious from the forum I'm posting in), and my teacher gave us an assignment this week regarding switch statements. I have a basic understanding of them, but I can't fully grasp the idea. She is wanting us to write a program where the user inputs a code between 1, 2 and 3. If the code is not one of those three numbers, an error message is displayed. However, if the code is correct, then the output supplies a list of countries that "are included in the trip package". She advises using a switch statement to display the countries included in the trip package, and that some cases will not have a break afterward. I have what I believe to be the gist of the code put together, but I feel like I am doing it incorrectly for the assignment. She included a note at the end of the description that states:
"For codes 1, 2 and 3 'France, Italy' is displayed. For codes 1 and 2 'Germany' is displayed. Thus proper placement of the statement:
cout << "France, Italy"; in the switch statement will result in the statement appearing only once in the switch statement."
The trip codes are as follows:
Trip Code (Countries)
1 (England, Netherlands, Germany, France, Italy)
2 (Germany, France, Italy)
3 (France, Italy)
Could someone review my code thus far and advise if I am misunderstanding how to accomplish this assignment?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using namespace std;
int main()
{
char choice;
cout << "Select from the following options for your European Trip Package\n"
<< "\tCode\t1\n"
<< "\tCode\t2\n"
<< "\tCode\t3\n";
cin >> choice;
switch (choice)
{
case '1': cout << "England, Netherlands" << endl;
case '2': cout << "Germany" << endl;
case '3': cout << "France, Italy" << endl;
break;
default: cout << "Error. Invalid Choice" << endl;
break;
}
system("pause");
return 0;
}
|