This is my code:
#include <iostream>
using namespace std;
const int MAX_LITERS_OF_MILK_PER_CARTON = 3.78;
const double COST_PER_LITER = 0.38;
const double PROFIT_PER_CARTON = 0.27;
int main(void)
{
// Write your main here
int litersOfMilk;
int numberOfCartonsNeeded;
double actualNumberOfCartonsNeeded;
double totalCostOfMilk;
double totalProfit;
// Get the liters of mild from the user
cout << "Enter the amount of milk in liters: ";
cin >> litersOfMilk;
cout << endl;
//Calculate the decimal number of milk cartons needed
actualNumberOfCartonsNeeded = static_cast<double> (litersOfMilk) / MAX_LITERS_OF_MILK_PER_CARTON;
//Calculate the number of cartons needed
numberOfCartonsNeeded = static_cast<int> (actualNumberOfCartonsNeeded + 0.5);
//Calculate the total cost of producing the milk today
totalCostOfMilk = litersOfMilk * COST_PER_LITER;
//Calculate the profit of the milk for today
totalProfit = litersOfMilk * (PROFIT_PER_CARTON/MAX_LITERS_OF_MILK_PER_CARTON);
//Output the number of cartons needed, the total cost of the milk & the profit to the screen
cout << "Number of Cartons Needed: " << numberOfCartonsNeeded << endl;
cout << "Total Cost to produce " << litersOfMilk << " liters: " << totalCostOfMilk << endl;
cout << "Total Profit to produce " << litersOfMilk << " liters: " << totalProfit << endl;
return 0;
}
When the program runs, every time there is division, it is doing integer division.
For example, the constant MAX_LITERS_OF_MILK_PER_CARTON is defined as 3.78, but when I divide by this constant, it is dividing by 3 instead of dividing by 3.78
How do I fix this?