In: Computer Science
C++ please
A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one liter of milk is $0.38, and the profit of each carton of milk is $0.27. Write a program that prompts the user to enter: The total amount of milk produced in the morning. The program then outputs: The number of milk cartons needed to hold milk. Round your answer to the nearest integer. The cost of producing milk. The profit for producing milk.
An input of 4900 must yield an output of:
How much milk did you produce? 4900 That is going to require 1296 cartons Total Cost to Produce: $1862 Total Profit: $349.92
Screenshot
Program
#include <iostream>
using namespace std;
//Constants
const double CARTON = 3.78;
const double PRODUCE = 0.38;
const double PROFIT = 0.27;
int main()
{
double milkProduced;
//Prompt for the milk produced
cout << "How much milk did you produce? ";
cin >> milkProduced;
//CAlculations and display result
cout << "That is going to require " <<
round(milkProduced / CARTON) << " cartons\n";
cout << "Total Cost to Produce : $" <<
milkProduced * PRODUCE << endl;
cout << "Total Profit : $" <<
round(milkProduced / CARTON) * PROFIT << endl;
}
-----------------------------------------------------------------
Output
How much milk did you produce? 4900
That is going to require 1296 cartons
Total Cost to Produce : $1862
Total Profit : $349.92