Question

A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons...

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 and the profit of each carton of milk vary from farm to farm. Write a program that prompts the user to enter: The total amount of milk produced in the morning. The cost of producing one liter of milk. The profit on each carton of milk. 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.

Please post in C++ and make sure the answer is able to be rounded to the nearest integer.

Homework Answers

Answer #1

// C++ program to calculate the total number of cartons of milk produced, total cost of producing the milk and total profit for producing the milk

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

       double milk_per_carton = 3.78; // given amount of liters of milk in one carton

       double total_milk, cost_per_liter, profit_per_carton;

       int num_carton;

       double profit, total_cost;

       // input the total amount of milk produced in liters

       cout<<"Enter the total amount of milk produced in the morning(in liters) : ";

       cin>>total_milk;

       // input of cost of producing one liter of milk

       cout<<"Enter the cost of producing one liter of milk : ";

       cin>>cost_per_liter;

       // input of profit on each carton of milk

       cout<<"Enter the profit on each carton of milk : ";

       cin>>profit_per_carton;

       num_carton =round( total_milk/milk_per_carton); // calculate the number of cartons needed

       profit = (num_carton*profit_per_carton); // calculate the total profit of producing the milk

       total_cost = cost_per_liter*total_milk; // calculate the total cost of producing the milk

      

       // output the number of cartons, total profit of producing the milk and total cost of producing the milk

       cout<<"The number of milk cartons needed to hold milk : "<<num_carton<<endl;

       cout<<"The cost of producing milk : $"<<fixed<<setprecision(2)<<total_cost<<endl;

       cout<<"The profit for producing milk : $"<<fixed<<setprecision(2)<<profit<<endl;

return 0;

}

//end of program

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT