Working out wastage for game
Aug 1, 2016 at 10:19am UTC
Hi i'm working on a game for my course and i'm stuck on trying to work out the wastage i know i need to work out the total lemons i have used and then minus the iLemonsneeded from it but i'm just not sure how to work it out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
const float iWater = 0.75;
const float iSugar = 0.25;
const float iLemon = 0.25;
int iNumberofdrinks;
const float iLemonadeprice = 1.05;
std::cout << "How many drinks would you like " ;
std::cin >> iNumberofdrinks;
std::cout << "Ingredients Needed \n" ;
float iWaterneeded = iWater * iNumberofdrinks;
float iSugarneeded = iSugar * iNumberofdrinks;
float iLemonneeded = iLemon * iNumberofdrinks;
std::cout << "Water needed: " << iWaterneeded << std::endl;
std::cout << "Sugar needed: " << iSugarneeded << std::endl;
std::cout << "Lemon needed: " << iLemonneeded << std::endl;
float iWastage =
std::cout << "\n" ;
std::cout << "Lemon wasted " << iWastage << std::endl;
std::cout << "\n" ;
float iprice = iNumberofdrinks * iLemonadeprice;
std::cout << std::setprecision(3) << "That will be $" << iprice << std::endl;
Aug 1, 2016 at 11:55am UTC
Use ceil() to get the smallest integer greater than or equal to a number. So iWastage is ceil(iLemonneeded) - iLemmonneeded;
Aug 1, 2016 at 4:55pm UTC
Thank you very much works great :D
Aug 2, 2016 at 7:13am UTC
Another way to get whole number of lemons to compare and therefore get 'wastage'.
1 2 3 4 5 6 7
int adjust(float aNumber)
{
if (aNumber - (int )aNumber > 0)
return int (aNumber) + 1;
else
return int (aNumber);
}
Topic archived. No new replies allowed.