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
what are the iterator and generic algorithms.
How would perform Pattern Matching in C++?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
What is the best c++ compiler for windows 10?
Should a constructor be public or private?
What are the implicit member functions of class?
Is it possible to provide special behavior for one instance of a template but not for other instances?
What is the identity function in c++? How is it useful?
Does c++ have finally?
What is a singleton c++?
What are the defining traits of an object-oriented language?
How do I start a c++ project?
What size is allocated to the union variable?
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
What is the protected keyword used for?