Question: In this exercise, you will experiment with the switch statement. a. Edit and run the Advanced20.cpp file (enclosed), The program uses the switch statement to
In this exercise, you will experiment with the switch statement.
a. Edit and run the Advanced20.cpp file (enclosed), The program uses the switch statement to display the names of the gifts mentioned in the song The Twelve Days of Christmas.
b. Run the program. When you are prompted to enter the day, type the number 1 and press Enter. The names of the gifts for the first through the twelfth days appear on the screen. Close the Command Prompt window.
c. Run the program again. When you are prompted to enter the day, type the number 9 and press Enter. The names of the gifts for the ninth through the twelfth days appear on the screen. Close the Command Prompt window.
d. Modify the program so that it displays only the name of the gift corresponding to the day entered by the user. For example, when the user enters the number 4, the program should display the 4 calling birds message only.
e. Save and then run the program. When you are prompted to enter the day, type the number 4 and press Enter. The 4 calling birds message should appear on the screen. Record your results on the word document and upload your solution to blackboard
//Advanced20.cpp - displays the names of the gifts in the //song "The Twelve Days of Christmas" //Created/revised byon #include using namespace std; int main() { int day = 0; cout << "Enter the day (1 through 12): "; cin >> day; switch (day) { case 1: cout << "1 partridge in a pear tree" << endl; break; case 2: cout << "2 turtle doves" << endl; break; case 3: cout << "3 french hens" << endl; break; case 4: cout << "4 calling birds" << endl; break; case 5: cout << "5 golden rings" << endl; break; case 6: cout << "6 geese a laying" << endl; break; case 7: cout << "7 swans a swimming" << endl; break; case 8: cout << "8 maids a milking" << endl; break; case 9: cout << "9 ladies dancing" << endl; break; case 10: cout << "10 lords a leaping" << endl; break; case 11: cout << "11 pipers piping" << endl; break; case 12: cout << "12 drummers drumming" << endl; break; default: cout << "Error in day number." << endl; } //end switch return 0; } //end of main function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
