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
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) // declaration of main...
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) // declaration of main function { int limit, // a user entered limit for a loop step, // a user entered step value x; // control variable for the loop cout << "Counting up from 1 to 10\n"; // The control variable x takes on values from 1 to 10 for (x = 1; x <= 10; x++) // for loop to count from 1 to 10 values...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main()...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main() { ​cout << "Hello, world." << endl; } Open a Word Document and copy and paste the program and the output. 2. Create a new program: #include <iostream> using namespace std; int main() { ​float num1; ​float num2 ​float avg; ​cout << "Enter two numbers" << endl; ​cin >> num1 >> num2; ​avg = num1 + num2/2; ​cout << "The average is " <<...
//Calculate the even parity for letters, (A, Z, D, a). #include <iostream> #include <bitset> using namespace...
//Calculate the even parity for letters, (A, Z, D, a). #include <iostream> #include <bitset> using namespace std; int main() { char c; int bitCounts, pBit;; while (cin>>c){ //ctrl-Z to stop bitset<8> bs(c); cout<<bs<<endl; bitCounts = bs.count(); pBit = bitCounts % 2? 1: 0; cout<<"Even Parity bit: "<<pBit<<endl; } }
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; }
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std;...
/* Displaying process segment addresses */ #include <iostream> extern int etext, edata, end; using namespace std; int main( ){ cout << "Adr etext: " << hex << int(&etext) << "\t "; cout << "Adr edata: " << hex << int(&edata) << "\t "; cout << "Adr end: " << hex << int(&end ) << "\n"; return 0; } please modify this above code and execute to get the output.
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 " ; }...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT