#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout << "Welcome to the Calorie Count-ulator!\n"; // Get user input: cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n"; cin >> meal_choice; cout << "Enter the amount of servings (1-9):\n"; cin >> servings; // TODO: Use a switch statement to evaluate the user's meal choice // Handle error checking where appropriate // Exit the program: return 0;}
Complete the program as follows:
Program:
#include <iostream>
using namespace std;
int main(){
char meal_choice; //user's choice
int servings, total_calories;
// Display greeting:
cout << "Welcome to the Calorie Count-ulator!\n";
// Get user input:
cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n";
cin >> meal_choice;
cout << "Enter the amount of servings (1-9):\n";
cin >> servings;
// TODO: Use a switch statement to evaluate the user's meal choice
switch(meal_choice){ /* Use switch statement to evaluate the user's meal choice */
case 'P': cout<<"\nYou have chosen Pizza.\n"; /* print the choice is 'Pizza' if meal_choice is 'P' */
break;
case 'S': cout<<"\nYou have chosen Salad.\n"; /* print the choice is 'Salad' if meal_choice is 'S' */
break;
case 'H': cout<<"\nYou have chosen Hamburger.\n"; /* print the choice is 'Hamburger' if meal_choice is 'H' */
break;
default: cout<<"\nInvalid choice..! Please enter a valid option.."; /* if the user enters any invalid choice, print error message */
}
if(servings>=1&&servings<=9){ /* check if servings is between 1 and 9 */
cout<<"\nAmount of servings : "<<servings; /* print servings */
}
else{
cout<<"Please enter a valid amount of servings..!"; /* Otherwise, print error message */
}
// Handle error checking where appropriate
// Exit the program:
return 0;
}
Screenshot:
Output:
Output2:
Please don't forget to give a Thumbs Up.
Get Answers For Free
Most questions answered within 1 hours.