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.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
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:"<<" "<<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.

I hope you can help me with my little problem
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

1
2
3
4
5
6
7
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.
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.