Simple Programming help in c++ Chapter 4: Using if statements The Quad is sellin
ID: 3871232 • Letter: S
Question
Simple Programming help in c++
Chapter 4: Using if statements The Quad is selling sandwiches, salads and platters as their specials for the month. If a customer orders 3 or more items of the same type, there is a special price. Sandwiches cost $3.50 each or $2.75 for 3 or more. Salads cost $4.50 each or $3.75 for 3 or more. Platters cost $6.50 each or $5.75 for 3 or more. Using the following sample inputs, write a program that will correctly calculate a person's order. Be sure to document the variables, constants and body of the code. Submit the code and screenshots Would you like a sandwich. a platter or a salad? platter How many platters would you like to buy? 2 Each platter is $6.50 The total for the platters : $13.00 Press any key to continue · ·- CWindows syste321cmd.exe Would you like a sandwich. a platter or a salad? sandwich How many sandwiches would you like to buy? 3 ch sandwich is S2.75 The total for the sandwiches $8.25 Press any key to continue · ·-Explanation / Answer
Source Code:
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
string choice;
int ch;
int noofitems;
double totalcost;
do
{
cout<<" Would you like a sandwich,a platter or a salad ";
cin>>choice;
if(choice=="platter")
{
ch=1;
}
else if(choice=="sandwich")
{
ch=2;
}
else if(choice=="salad")
{
ch=3;
}
else
{
ch=4;
}
switch(ch)
{
case 1:
cout<<"How many platters would you like to buy ";
cin>>noofitems;
if(noofitems>=3)
{
cout<<" Each platter is $5.75";
totalcost=(5.75)*noofitems;
}
else
{
cout<<" Each platter is $6.5";
totalcost=(6.5)*noofitems;
}
cout<<" The total for platters<s> $:"<<totalcost;
break;
case 2:
cout<<"How many sandwich would you like to buy ";
cin>>noofitems;
if(noofitems>=3)
{
cout<<" Each sandwich is $2.75";
totalcost=(2.75)*noofitems;
}
else
{
cout<<" Each sandwich is $3.5";
totalcost=(3.5)*noofitems;
}
cout<<" The total for sandwich<s> $:"<<totalcost;
break;
case 3:
cout<<"How many salads would you like to buy ";
cin>>noofitems;
if(noofitems>=3)
{
cout<<" Each salads is $3.75";
totalcost=(3.75)*noofitems;
}
else
{
cout<<" Each salads is $4.5";
totalcost=(4.5)*noofitems;
}
cout<<" The total for salads<s> $:"<<totalcost;
break;
default:cout<<" Sorry we do not sell that item ";
}
}while(ch!=4);
}
Output:
Would you like a sandwich,a platter or a salad platter
How many platters would you like to buy 2
Each platter is $6.5
The total for platters<s> $:13
Would you like a sandwich,a platter or a salad sandwich
How many sandwich would you like to buy 3
Each sandwich is $2.75
The total for sandwich<s> $:8.25
Would you like a sandwich,a platter or a salad salad
How many salads would you like to buy 3
Each salads is $3.75
The total for salads<s> $:11.25
Would you like a sandwich,a platter or a salad fries
Sorry we do not sell that item
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.