Question

#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout...

#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;}

Homework Answers

Answer #1

Complete the program as follows:

  1. Use switch statement to evaluate the user's meal choice
  2. print the choice is 'Pizza' if meal_choice is 'P'
  3. print the choice is 'Salad' if meal_choice is 'S'
  4. print the choice is 'Hamburger' if meal_choice is 'H'
  5. if the user enters any invalid choice, print error message
  6. check if servings is between 1 and 9
  7. print servings
  8. Otherwise, print error message

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile;...
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; }...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;     float f=2.22;     float h=-7.5;     char a='S';     char b='M';     cout<<i<<"\t"<<j<<"\t"<<k<<endl;     Cout<<f<<"\t"<<h<<endl;     cout<<a<<"\t"<<b<<endl;     return 0;     }
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;   ...
What is value ofmyInt? #include <iostream> using namespace std; int main() {    int myInt;    int* myScore;    int myVar;       myInt = 10;    myScore = &myInt;    myVar = 20;    myVar = *myScore;    *myScore = 30;    myVar = 40;    myVar = *myScore;    } Group of answer choices 30 20 10 0
Consider the following program: #include #include #include using namespace std; int main() { int num1; int...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int num2; cout << fixed << showpoint << setprecision(2); cout << "Enter two integers: "; cin >> num1 >> num2; cout << endl; if (num1 != 0 && num2 != 0) cout << sqrt(abs(num1 + num2) + 0.5) << endl; else if (num1 != 0) cout << floor(num1 + 0.5) << endl; else if (num2 != 0) cout << ceil(num2 + 0.5) << endl; else...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse...
I have an error but i can't correct it #include <iostream> using namespace       std; long reverse (long       num, long   equation,long reverse = 0); int       main() {               long       num, reverse = 0;        cout << "Enter       the       num:       ";        cin >> num;        cout << "Reverse       num       is       =       "               << reverse << endl;        return       0; } long reverse(long       num, long equation, long reverse = 0) {        while (num)        {               equation...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT