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.38, and the profit of each carton of milk is $0.27. Write a C++ program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.

Answer Posted / hasan

#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;
}

Is This Answer Correct ?    11 Yes 25 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you overload the operator+ for short integers?

601


What are the advantages of using const reference arguments in a function?

622


what does the following statement mean? int (*a)[4]

623


Name the operators that cannot be overloaded in C++?

589


What number of digits that can be accuratly stored in a float (based on the IEEE Standard 754)? a) 6 b) 38 c) An unlimited number

792






What is a storage class? Mention the storage classes in c++.

596


Why is that unsafe to deal locate the memory using free( ) if it has been allocated using new?

635


What is the difference between reference and pointer?

615


Explain class invariant.

589


Why c++ is the best language?

596


What is a storage class used in c++?

618


Discuss the possibilities related to the termination of a program before entering the mainq method?

546


Which is better c++ or java?

567


What are c++ variables?

542


What is buffering in c++?

589