#include <iostream>
usingnamespace std;
int main()
{
float a;
float b;
float c;
float e;
cout <<"type 0.68 if you are male or 0.55 if you are a woman:\n";
cin>> a;
cout << "hours you've been drinking:\n";
cin >> b;
cout<<"number of beers:\n";
cin >> c;
double d = c * 12.0; // grams of alchohol ex. 15 * 12 = 180g pure alchohol
cout <<"type your weigth:\n";
cin>> e;
// pure alcohol in gram / weigth * waterpercent
cin.ignore();
float f = e / 10.0 * b; // the pr hour burn ex. 72 / 10 * 3 = 21,6
float g = e * a;
float h = d - f;
double result = h / g;
if (result>=0.5){
cout<<"you are too drunk to drive, you BAC is:"<<" "<<result<<endl;
cin.get();
return (0);
}
if (result<=0.5){
cout<<"you can drive, but be carefull:" << " "<<endl;
return (0);
}
return 0;
}
alright, that isnt the worst code ive ever seen but it could use a decent amount of work. first of all if you want to select gender, declare a variable of type "string" (no quotes) and name it "gender". then prompt the user to input the string....
1 2
cout << "Please enter your gender. M/F: ";
cin >> gender;
then when changing the formula for each gender....
1 2 3 4 5 6
if (gender == "m" || gender == "M"){
//the formula for male BAC
}
else {
//the formula for female BAC
}
double result = h / g;
if (result>0.5){
cout<<"you are too drunk to drive, you BAC is:"<<" "<<result<<endl;
cin.get();
}
else{
cout<<"you can drive, but be carefull:" << " "<<endl;
cin.get();
}
return 0;
this part always so matter what the answer is it prints cout<<"you can drive, but be carefull:" << " "<<endl;