So I'm trying to make a BAC table. But the problem is the math isn't coming back right. Like it just keeps saying 0.00 and nothing else. But that isn't right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void computeBloodAlcoholConcentration(int numDrinks, int weight,
int duration, double &maleBAC, double &femaleBAC)
{
// to get the right .01 value
double y = ((duration / 40.0) * 0.100000);
double x = (numDrinks / weight);
femaleBAC = (x * 4.5);
maleBAC = (x * 3.8);
//so i only get two decimal points
std::cout.precision(2);
if (x == 0.00)
{
cout << numDrinks << " " << std::fixed << femaleBAC - y << " " << "Safe to Drive" << endl;
cout << numDrinks << " " << std::fixed << maleBAC - y << " " << "Safe to Drive" << endl;
}
It's a lot bigger than this, but I don't think I need all of it to fix the problem.
Any help would be great. Thanks!!
Okay that works but is there another way? I need to keep them both as int by the rules of the program I'm doing. (I don't really know why it is restricted to that ) but the program that needs to check my answer is not happy with that way of it working
If you want floating point arithmetic, one must involve floating point types.
[quote](I don't really know why it is restricted to that ) but the program that needs to check my answer is not happy with that way of it working [/quoe]
I didn't way to change the type. I said to cast the variable to double.
double x = ((double)numDrinks / weight);
Or the wordier C++ cast:
double x = (static_cast<double>(numDrinks) / weight);
now its not doing the subtraction part for that y. So do I change that to where I get the variables for femaleBAC and maleBAC, or do I put that math somewhere else. The constant is -.01 for every 40 minutes.