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
Can a program run without main function?
What information can an exception contain?
Which software is best for programming?
Why do we use the using declaration?
What are the extraction and insertion operators in c++? Explain with examples.
What is #include iomanip?
Explain the difference between overloading and overriding?
What is the v-ptr?
Is facebook written in c++?
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
What is the best way to declare and define global variables?
What is the use of dot in c++?
Is c better than c++?
Explain the volatile and mutable keywords.
What gives the current position of the put pointer?