Write a program that does the following using c++ programing language. A milk ca
ID: 3534065 • Letter: W
Question
Write a program that does the following using c++ programing language. A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. Write a program that does the following:
a. Prompt the user to enter the total amount of milk in liters produced in the morning.
b. Prompt the user to enter the cost of producing one liter of milk.
c. Prompt the user to enter the profit on each carton of milk.
d. Outputs the number of milk cartons needed to hold milk. (Round your answer to nearest integer.)
e. Outputs the cost of producing milk.
f. Outputs the profit for producing milk.
g. Format the output of decimal numbers with two decimal places
Explanation / Answer
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
double milkAmt = 0.0, profitPerMilk = 0.0,costPerMilk = 0.0;
cout<<"total amount of milk in liters produced in the morning: ";
cin>>milkAmt;
cout<<"enter the cost of producing one liter of milk: ";
cin>>costPerMilk;
cout<<"enter the profit on each carton of milk: ";
cin>>profitPerMilk;
int cartoonNum = (int)(milkAmt/ 3.78)+1;
cout<<"The number of milk cartons needed to hold milk : "<<cartoonNum<<endl;
cout.setf(ios::fixed);
cout<<" the cost of producing milk : "<<setprecision(2)<<(costPerMilk*milkAmt)<<endl;
cout.setf(ios::fixed);
cout<<"profit for producing milk : "<<setprecision(2)<<(profitPerMilk*milkAmt)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.