Concept explainers
Explanation of Solution
Purpose of the given code:
The purpose of the given code is to find the fat grams for the ice cream flavor that is entered by the user.
Program:
The “if…else if” statements are highlighted below.
//Include required header files
#include<iostream>
#include<cstring>
using namespace std;
// Main function
int main()
{
//Declare constant variable
const int LENGTH = 20;
//Declare array of characters
char iceCream[LENGTH];
//Print the statements
cout<<"What flavor of ice cream do you like best? ";
cout<<"Chocolate, Vanilla, or Pralines and Pecan? ";
//Get a flovor from the user
cin.getline(iceCream, LENGTH);
//Print the statements
cout<<"Here is the number of fat grams for a half ";
cout<<"cup serving:\n";
//Check if the user enters "Chocolate"
if(strcmp(iceCream,"Chocolate")==0)
//Print the statement
cout<<"Chocolate: 9 fat grams.\n";
//Check if the user enters "Vanilla"
else if(strcmp(iceCream,"Vanilla")==0)
//Print the statement
cout<<"Vanilla: 10 fat grams.\n";
//Check if the user enters "Pralines" or "Pecan"
else if((strcmp(iceCream,"Pralines")==0)||(strcmp(iceCream,"Pecan")==0))
//Print the statement
cout<<"Pralines and Pecan: 14 fat grams...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Starting Out with C++: Early Objects
- #include<stdio.h> #include<stdarg.h> void fun1(int num, ...); void fun2(int num, ...); int main() { fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0; } void fun1(int num, ...) { char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str); } void fun2(int num, ...) { va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num); }.arrow_forwardVoid Do1 (int: &, a. int &b) { a = 5; a = a + b; b = a + 2; } Int main() { Int x = 10; Do1 (x,x); Cout << x << endl; } The output of this program isarrow_forward#include using namespace std; int main() int x=1,y=2; for (int i=0; i<3; i++) e{ x=x*y; 8{ } cout<arrow_forwardEXPLAIN THIS CODE EACH LINE #include <stdio.h>#include<string.h>int main(){ char name[20]; int meal,quantity; int drink,quantity2; char choose_meal[30] = ""; int meal_price; float drink_price, orderPrice; char choose_drink[30] = ""; float cash, change; printf("--------------------Marry's Fast Food--------------------"); printf("\n"); printf("Enter your name: "); scanf("%s", name); printf("Hello %s!\n", name); printf("\n\nWhat would you like to order?\n"); printf("------------------------MEALS------------------------\n\n"); printf("[1] 1 pc. Chicken Joy....................Php 76.00\n"); printf("[2] 1 pc. w/Jolly spaghetti..............Php 99.00\n"); printf("[3] pc. Spaghetti........................Php 55.00\n"); printf("[4] pc. Burger steak w/rice..............Php 85.00\n"); printf("[5] pc. Burger...........................Php 30.00\n\n"); printf("Choose a number…arrow_forward== include using namespace std; # int main () { int a = 14; do { if( a 15) { a = a + 1; } cout << a <<" "; a = a + 1; } while( a < 16 ); } الجواب: إجابةarrow_forwardstruct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statement that sets the first [0] title of Awesome to Best.arrow_forward1 using System; 2 using System.Text; 3 class Program { staticvoid Main(string[] args) { int choice,games_choice; Console.WriteLine("You are on a quest for a rare flavor of chips you saw on an ad. The inside of the bag has an invaluable prize that could change your life forever. You decide to dedicate today to find that bag of chips. Do you go to Walmart or Costco first?"); Console.Write("Press 1 for 'Walmart' or Press 2 for 'Costco'\n"); choice = int.Parse(Console.ReadLine()); if(choice==1) { Console.WriteLine("You begin your meticulous search in the isles of the Walmart Supercenter only to find an empty display of the newly released rare flavor of chips. Out of the corner of your eye you see a nearby shopper with three bags of those rare chips in her basket casually strolling along. Craziness pops in your head and you have to make a quick decision. Your first option is to ask her nicely for one of the bags but that just seems far fetched. Your second option is to challenge her to a…arrow_forwardC++ Please Help!arrow_forwardThe following declaration, program, and program segment has errors. Locate as many as you can. #include <iostream> using namespace std;class DumbBell; { int weight; public: void setWeight(int); };void setWeight(int w) { weight = w; }int main() { DumBell bar; DumbBell.setWeight(200); cout << "The weight is " << bar.weight << endl; return 0;}arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education