### cout<<"you'll need to wait " << x << " hours before you can drive";

I do know that the program is abit messy, but here it is.
This is my very first tutoriel free program.

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 #include #include using namespace std; int main() { string gender; float water; float hours; float drinks; float weight; cout << "Please enter your gender. M/F: "; cin >> gender; if (gender == "M" || gender == "m"){ water = 0.68; } if (gender == "F" || gender == "f"){ water = 0.55; } cout << "hours you've been drinking "; cin >> hours; cout<<"number of beers "; cin >> drinks; double pureA = drinks * 12.0; // grams of alchohol ex. 15 * 12 = 180g pure alchohol cout <<"type your weights "; cin>> weight; // pure alcohol in gram / weight * waterpercent cin.ignore(); float burn = (weight / 10.0) * hours; // the pr hour burn ex. 72 / 10 * 3 = 21,6 float g = weight * water; // Weight * water float h = pureA - burn; // the overall pure alcohol - the burn double result = h / g; // the BAC int x; if (result >= 0.5){ cout<<"you are too drunk to drive, you BAC is:"<<" "<

I want to draw attention till the
 1234567 if (result >= 0.5){ cout<<"you are too drunk to drive, you BAC is:"<<" "<

part of the code. I want the program to messure how many hours you need to wait before you can e.g drive again.

Say if the result is over 0.5 how many hours do you need to wait before the result is <0.5?

Since the program already have all the data such as: Weight, grams of alcohol in the body after the burn etc. It should be fairly simple i guess.. i just havent learned how to make the program do the math itself.

I hope you can help me with my little problem
closed account (LN7oGNh0)
Your code is quite long. I think you should organize everything into some sort of formula. So the amount could be shown in one function. (just a suggestion). :)
Last edited on
For eksample cutting out the

 1234567 float burn = (weight / 10.0) * hours; // the pr hour burn ex. 72 / 10 * 3 = 21,6 float g = weight * water; // Weight * water float h = pureA - burn; // the overall pure alcohol - the burn double result = h / g; // the BAC

part.. problem is that i tried to do this, but keep getting the wrong result. only way i got the result i wanted was like the exhibit. Its most likely just me who suck at math but yea i can see your point. :)
closed account (LN7oGNh0)
Could you tell me exactly what your program is supposed to do. (I would read through it but I havent got the time.) So, what steps to get to the final result.
I dont need code, justa simple explanation then I will probably be able to help you.
The users enters the information, weigth gender, how much and how long from first till last drink. and then calculate the BAC.

It does print the BAC double result

but i want it to take the calculations on and tell the user exactly how many hours they need to wait to get sober :)

as simple as that. but since this is my first program i got no idea how to do so.
Topic archived. No new replies allowed.