A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships car
ID: 3846862 • Letter: A
Question
A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. Each carton can hold 3.78 liters of milk. Write a program that allows the user to enter the cost of producing one liter of milk, the profit on each carton of milk, and the total amount of milk produced that day. The program then calculates and displays the number of milk cartons needed to hold the milk, the cost of producing the milk and the profit for that day.
Need: source code
The name of program as a comment at the top of the file
IPO chart incorporated as comments after the name of the file
A test plan or a screen shot of your test results
Explanation / Answer
Here is the C++ program for the above given scenario:
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double milkProduced, cartonsRequired;
const double cartonSize = 3.78;
const double productionCost = 0.38;
const double cartonProfit = 0.27;
cout << "How much milk did you produce? ";
cin >> milkProduced;
cartonsRequired = milkProduced / cartonSize;
cout << fixed << showpoint << setprecision(2);
cout << "That is going to require " << static_cast<int>(cartonsRequired) << " cartons" << endl;
cout << "Total Cost to Produce: $" << cartonsRequired * productionCost << endl;
cout << "Total Profit: $" << cartonsRequired * cartonProfit << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.