Question

C++ programming exercise: A milk carton can hold 3.78 liters of milk. Each morning, a dairy...

C++ programming exercise:

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:

  1. The total amount of milk produced in the morning.

  2. The cost of producing one liter of milk.

  3. The profit on each carton of milk.

The program then outputs:

  1. The number of milk cartons needed to hold milk.

    • Round your answer to the nearest integer.
  2. The cost of producing milk.

  3. The profit for producing milk.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>
#include <iomanip>
#include<cmath>

using namespace std;

int main()
{
   //constant to indicate how many liters of milk can each carton hold
   const double MILK_IN_EACH_CARTON = 3.78;
   //variable declarations
    double milkProduced, productionCostPerLiter, profitPerCarton;
    int cartonsRequired;
    double costOfProducingMilk, profit;
  
    //prompt and read milk produced
    cout << "Enter total amount of milk produced in the morning: ";
    cin >> milkProduced;
    //prompt and read cost of producing 1 liter of milk
    cout << "Enter the cost of producing one liter of milk: ";
    cin >> productionCostPerLiter;
    //prompt and read profit on each carton of milk
    cout << "Enter profit on each carton of milk: ";
    cin >> profitPerCarton;
  
    //calculate the number of carton required
    cartonsRequired = (round) (milkProduced / MILK_IN_EACH_CARTON);
    //calculate the cost of producing milk
    costOfProducingMilk = productionCostPerLiter * milkProduced;
    //calculate the profit
    profit = cartonsRequired * profitPerCarton;
  
    //display output
    cout << "\nNumber of cartons required: " << cartonsRequired << endl;
    cout << "Cost for producing milk: $" << fixed << setprecision(2) << costOfProducingMilk << endl;
    cout << "Profit for producing milk: $" << fixed << setprecision(2) << profit << endl;
    return 0;
}

Output:

Program Screenshot:

Add a comment
Know the answer?
Add Answer to:
C++ programming exercise: A milk carton can hold 3.78 liters of milk. Each morning, a dairy...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Please 1. A milk carton can hold 3.78 litres of milk. Each morning, a dairy...

    C++ Please 1. A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.2, and the profit of each carton of milk is $0.04. 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. (Round...

  • c++ please A farmer ships bottles of olive oil to a supermarket. Each olive oil bottle...

    c++ please A farmer ships bottles of olive oil to a supermarket. Each olive oil bottle holds 2.5 liters of oil. The cost of producing one liter of olive oil is 1.2 JD, and the profit of each bottle of oil is 0.35 JD. Write a program that does the following: 1. Prompts the user to enter the total amount of oil (liters) produced. 2. Outputs the number of olive oil bottles needed to hold olive oil produced. (Round the...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT