Question

In: Computer Science

/* Homework Lab 8 Nested If statements Write the nested decision logic to print the recommended...

/* Homework Lab 8

Nested If statements

Write the nested decision logic to print the recommended meal
based on the user's choices for Restaurant and Load given the table
shown below:

Restaurant Preference Meal
-----------------------------------------------------
(M)cDonald's
(B)eef Quarter Pounder
           (C)hicken Chicken McNuggets
           (F)ish Filet-o-Fish
           (S)alad Side Salad
(O)utback
           (B)eef Ribeye
           (C)hicken Alice Springs Chicken
           (F)ish Grilled Tilapia
           (S)alad Aussie Cobb Salad
(G)ibsons
           (B)eef Bone-in Filet Mignon
           (C)hicken Whole Spit-Roasted Chicken
           (F)ish Grilled Norwegian Salmon
           (S)alad Alaskan King Crab Salad

For example, if the user chooses '(M)cDonald's' and '(B)eef'
then the appropriate response should be "Quarter Pounder"

If the user makes any selection other than B, b, C, c, F, f,
S, or s then the approprate response should be:
"You entered an invalid meal preference selection."

*/

#include<iostream>
#include<cctype> // for toupper()
using namespace std;

int main()
{
   // Declare program variables for user input.
   char restaurantChoice;
   char mealPreference;

   // Prompt and get user's choice for restaurant.
   cout << "Enter your choice for Restaurant" << endl
       << "(M)cDonald's, (O)utback, or (G)ibsons: ";
   cin >> restaurantChoice;

   // Ensure restaurantChoice is uppercase
   restaurantChoice = toupper(restaurantChoice);

   // Prompt and get user's choice for meal preference.
   cout << "\nEnter your meal preference:" << endl
       << "(B)eef, (C)hicken, (F)ish, (S)alad: ";
   cin >> mealPreference;

   // Ensure mealPreference is uppercase
   mealPreference = toupper(mealPreference);

   cout << endl;

   // For each chosen Restaurant,
   // output an appropriate response based on Meal Preference.

   if (restaurantChoice == 'M') // McDonald's
   {
       cout << "You chose McDonald's." << endl;

       // TODO: Write an extened if-else-if based on the user's choice
       // for Meal Preference to print one of the following messages:
       //   
       // B = Quarter Pounder
       // C = Chicken McNuggets
   // F = Filet -o- Fish
       // S = Side Salad
       // Otherwise = You entered an invalid meal preference selection.

       cout << endl;

   }
   else if (restaurantChoice == 'O') // Outback
   {
       cout << "You chose Outback." << endl;

       // TODO: Write an extened if-else-if based on the user's choice
       // for Meal Preference to print one of the following messages:
       //   
       // B = Ribeye
       // C = Alice Springs Chicken
   // F = Grilled Tilapia
       // S = Aussie Cobb Salad
       // Otherwise = You entered an invalid meal preference selection.

       cout << endl;
      
   }
   else if (restaurantChoice == 'G') // Gibsons
   {
       cout << "You chose Gibsons." << endl;

       // TODO: Write an extened if-else-if based on the user's choice
       // for Meal Preference to print one of the following messages:
       //   
       // B = Bone-in Filet Mignon
       // C = Whole Spit-Roasted Chicken
       // F = Grilled Norwegian Salmon
       // S = Alaskan King Crab Salad
       // Otherwise = You entered an invalid meal preference selection.

       cout << endl;

   }
   else // Invalid Restaurant selection
       cout << "You entered an invalid restaurant selection: "
       << restaurantChoice << endl;

   cout << "\nEnd Program" << endl;

   return 0;
}

/*
Sample Program Output
-----------------------------------------------------------

Test #1
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: X

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: B

You entered an invalid restaurant selection: X

End Program
Press any key to continue . . .

Test #2
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: X

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: X

You entered an invalid restaurant selection: X

End Program
Press any key to continue . . .

Test #3
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: M

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: B

You chose McDonald's.
We recommend Quarter Pounder.

End Program
Press any key to continue . . .

Test #4
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: m

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: c

You chose McDonald's.
We recommend Chicken McNuggets.

End Program
Press any key to continue . . .

Test #5
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: M

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: F

You chose McDonald's.
We recommend Filet-o-Fish.

End Program
Press any key to continue . . .

Test #6
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: m

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: S

You chose McDonald's.
We recommend Side Salad.

End Program
Press any key to continue . . .

Test #7
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: M

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: X

You chose McDonald's.
You entered an invalid meal selection.

End Program
Press any key to continue . . .

Test #8
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: O

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: B

You chose Outback.
We recommend Ribeye.

End Program
Press any key to continue . . .

Test #9
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: o

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: c

You chose Outback.
We recommend Alice Springs Chicken.

End Program
Press any key to continue . . .

Test #10
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: O

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: F

You chose Outback.
We recommend Grilled Tilapia.

End Program
Press any key to continue . . .

Test #11
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: o

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: s

You chose Outback.
We recommend Aussie Cobb Salad.

End Program
Press any key to continue . . .

Test #12
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: o

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: x

You chose Outback.
You entered an invalid meal selection.

End Program
Press any key to continue . . .

Test #13
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: G

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: b

You chose Gibsons.
We recommend a Bone-in Filet Mignon.

End Program
Press any key to continue . . .

Test #14
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: G

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: C

You chose Gibsons.
We recommend Whole Spit-Roasted Chicken.

End Program
Press any key to continue . . .

Test #15
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: g

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: f

You chose Gibsons.
We recommend Grilled Norwegian Salmon.

End Program
Press any key to continue . . .

Test #16
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: g

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: S

You chose Gibsons.
We recommend Alaskan King Crab Salad.

End Program
Press any key to continue . . .

Test #17
================================
Enter your choice for Restaurant
(M)cDonald's, (O)utback, or (G)ibsons: G

Enter your meal preference:
(B)eef, (C)hicken, (F)ish, (S)alad: X

You chose Gibsons.
You entered an invalid meal selection.

End Program
Press any key to continue . . .

*/

Solutions

Expert Solution

CODE

#include<iostream>

#include<cctype> // for toupper()

using namespace std;

int main()

{

// Declare program variables for user input.

char restaurantChoice;

char mealPreference;

// Prompt and get user's choice for restaurant.

cout << "Enter your choice for Restaurant" << endl

<< "(M)cDonald's, (O)utback, or (G)ibsons: ";

cin >> restaurantChoice;

// Ensure restaurantChoice is uppercase

restaurantChoice = toupper(restaurantChoice);

// Prompt and get user's choice for meal preference.

cout << "\nEnter your meal preference:" << endl

<< "(B)eef, (C)hicken, (F)ish, (S)alad: ";

cin >> mealPreference;

// Ensure mealPreference is uppercase

mealPreference = toupper(mealPreference);

cout << endl;

// For each chosen Restaurant,

// output an appropriate response based on Meal Preference.

if (restaurantChoice == 'M') // McDonald's

{

cout << "You chose McDonald's." << endl;

if (mealPreference == 'B' || mealPreference == 'b' ) {

cout << "We recommend Quarter Pounder." << endl;

} else if (mealPreference == 'C' || mealPreference == 'c' ) {

cout << "We recommend Chicken McNuggets." << endl;

} else if (mealPreference == 'F' || mealPreference == 'f' ) {

cout << "We recommend Filet-o-Fish." << endl;

} else if (mealPreference == 'S' || mealPreference == 's' ) {

cout << "We recommend Side Salad." << endl;

} else {

cout << "You entered an invalid meal selection." << endl;

}

cout << endl;

}

else if (restaurantChoice == 'O') // Outback

{

cout << "You chose Outback." << endl;

if (mealPreference == 'B' || mealPreference == 'b' ) {

cout << "We recommend Ribeye." << endl;

} else if (mealPreference == 'C' || mealPreference == 'c' ) {

cout << "We recommend Alice Springs Chicken." << endl;

} else if (mealPreference == 'F' || mealPreference == 'f' ) {

cout << "We recommend Grilled Tilapia." << endl;

} else if (mealPreference == 'S' || mealPreference == 's' ) {

cout << "We recommend Aussie Cobb Salad." << endl;

} else {

cout << "You entered an invalid meal selection." << endl;

}

cout << endl;

}

else if (restaurantChoice == 'G') // Gibsons

{

cout << "You chose Gibsons." << endl;

if (mealPreference == 'B' || mealPreference == 'b' ) {

cout << "We recommend Bone-in Filet Mignon." << endl;

} else if (mealPreference == 'C' || mealPreference == 'c' ) {

cout << "We recommend Whole Spit-Roasted Chicken." << endl;

} else if (mealPreference == 'F' || mealPreference == 'f' ) {

cout << "We recommend Grilled Norwegian Salmon." << endl;

} else if (mealPreference == 'S' || mealPreference == 's' ) {

cout << "We recommend Alaskan King Crab Salad." << endl;

} else {

cout << "You entered an invalid meal selection." << endl;

}

cout << endl;

}

else // Invalid Restaurant selection

cout << "You entered an invalid restaurant selection: "

<< restaurantChoice << endl;

cout << "\nEnd Program" << endl;

return 0;

}


Related Solutions

C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows: 0 0 1 0 1 2 0 1 2 3 … 0 1 2 3 … n-1
JAVA Write nested while loop that will print out this pattern, based upon a number entered...
JAVA Write nested while loop that will print out this pattern, based upon a number entered by the user. User enters 4: 1234 1234 1234 1234 User enters 2: 12 12
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
5. Write a C++ statement or statements that will:       Print the first two digits and the  last...
5. Write a C++ statement or statements that will:       Print the first two digits and the  last two digits of any 4 digit number stored in an integer variable n.         For example, given int n = 5623, print 56    23. 6. Write  C++ statements that will align the following three lines as printed in two 20 character columns. Name                                                 Years President Abraham Lincoln                                 1860-1865 Thomas Jefferson                               1801-1809 7.  Write a C++ statement or statements that will Output if a string has a length greater than 10, equal...
Write a computer program for a logic bomb that continually generates 8-digit numbers randomly and increases...
Write a computer program for a logic bomb that continually generates 8-digit numbers randomly and increases a counter by one each time. If the random number meets the current date in a format mmddyyyy, it will display 6 times on screen the following message: Today is [date]! The count is: [nnnn] Hint: Since everyday is a different date, don’t hard code the date in your program. And the [nnnn] should be the number from your counter.
In java Write multiple if statements: If carYear is before 1967, print "Probably has few safety...
In java Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has head rests.". If after 1991, print "Probably has anti-lock brakes.". If after 2002, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has head rests. Probably has anti-lock brakes. public class SafetyFeatures { public static void main (String [] args) { int carYear; carYear = 1991; *insert...
Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without...
Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has head rests.". If after 1991, print "Probably has anti-lock brakes.". If after 2002, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has head rests. Probably has anti-lock brakes. I want the answers in C++ not in java script data type
Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without...
Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has head rests.". If after 1992, print "Probably has anti-lock brakes.". If after 2000, print "Probably has tire-pressure monitor.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has head rests. Probably has anti-lock brakes. public class SafetyFeatures { public static void main (String [] args) { int carYear; carYear = 1968;
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT