#include <iostream>
#include <string>
usingnamespace 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:"<<" "<<result<<endl;
int x = result
cout<<"you'll need to wait " << x << " hours before you can drive";
cin.get();
}
else
{cout << "you can drive but be careful";
cin.get();
}
return 0;
}
I want to draw attention till the
1 2 3 4 5 6 7
if (result >= 0.5){
cout<<"you are too drunk to drive, you BAC is:"<<" "<<result<<endl;
int x = result
cout<<"you'll need to wait " << x << " hours before you can drive";
cin.get();
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.
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). :)
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. :)
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.