C++ question, please answer in the format of a beginner in order to make it easi
ID: 3824537 • Letter: C
Question
C++ question, please answer in the format of a beginner in order to make it easier to understand!
Thank, explain very throughly
1) 30 points] You've been hired by Milk Lovers Grocery Store to write software to calculate and display the cost to a customer of buying milk. Write a C+ program similar to Hwk03 to prompt for and read the following information from a clerk: Milk type (str -the type ofmilk purchased by the customer. The clerk only needs to enter a single-character code. You will need an if statement to determine which milk type the customer is buying. Use this table for the cost of each type: Milk code Milk type Cost per gallon Whole w or W $4.00 t or T $3.00 S or S Skim Number of gallons (int) the number of gallons of milk purchased by the customer. Output the following, one per line, with the label in one column and the value in another column: The two inputs (milk type should be spelled out The cost of a gallon ofmilk The cost of the milk nurchase (cost ner gallon k number of gallons)Explanation / Answer
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
//variable declarations
char milkType;
int numberOfGallons;
double costPerGallon;
cout<<"Milk Lovers grocery Store";
cout<<" =========================";
cout<<" Enter the milk type w-Whole t-2percent s-skim";
cin>>milkType;//input milkType
//base on milk type determine its costPerGallon
if(milkType == 'w' || milkType =='W')
costPerGallon = 4;
else if(milkType == 't' || milkType =='T')
costPerGallon = 3.5;
if(milkType == 's' || milkType =='S')
costPerGallon = 3;
cout<<fixed<<setprecision(2);//set decimal precision to 2 decimal placesusing iomanip header file
cout<<" Enter the gallons";
cin>>numberOfGallons;
cout<<left<<" Milk type purchased "<<right<<setw(15)<<milkType;//right manipulator used for justification
cout<<" Gallons purchased "<<right<<setw(15)<<numberOfGallons;
cout<<" Cost per gallon $"<<right<<setw(15)<<costPerGallon;
cout<<" Total $"<<right<<setw(15)<<numberOfGallons*costPerGallon;
cout<<" End of Milk Lovers grocery Store";
return 0;
}
output:
Milk Lovers grocery Store
=========================
Enter the milk type w-Whole t-2percent s-skim
Enter the gallons
Milk type purchased s
Gallons purchased 6
Cost per gallon $ 3.00
Total $ 18.00
End of Milk Lovers grocery Store
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.