C++:Problem4

Problem:
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 does the following:

a. Prompts the user to enter the total amount of milk produced in the morning.
b. Outputs the number of milk cartons needed to hold milk. You must have whole milk cartons. You can not sell a part of a milk carton.
c. Outputs the cost of producing milk.
d. Outputs the profit of producing milk.

Objective:
• Arithmetic calculation
• Formatting decimals
• proper indentation of statements
• proper usage of comment statements
• user-friendly input/out

Display:
Enter the total number of liters: 100
The total number of liters = 100
Amount of cartons = 26.46 Can't sell part of carton!!
Total cartons = 26
Total cost = $38.00

Total profit = $7.02
End of Program

Code:
#include
#include
using namespace std;

int main ()
{

//Input variables
double LitersMilkProduce;

//Output variables
double cartons, totalcost, totalprofit;

//Program variables
const double LITERCOST(0.38), CARTONPROFIT(0.27), LITERS_PER_CARTONS= (3.78);

//Prompt the user for input
cout << "Enter the total number of liters: ";
cin >> LitersMilkProduce;


//Calculation
cartons = LitersMilkProduce / LITERS_PER_CARTONS;
totalcost = LitersMilkProduce * LITERCOST;
totalprofit = static_cast(cartons) * CARTONPROFIT;

//Display output

cout << "The total number of liters = " << LitersMilkProduce << endl;
cout << fixed << showpoint<< setprecision(2) << "Amount of cartons = " << cartons << " Can't sell part of carton!!"
<< endl << "\t Total cartons = "<< static_cast(cartons) << endl
<< "Total cost = $"<< totalcost << endl << endl <<"Total profit = $" << totalprofit;


//closing
cout << "\nEnd of Program\n\n";
return 0;
}