I get the wrong results

Hello. i have a problem more with my 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
#include <iostream>
#include <string>
using namespace std;

int main()
 {


 string gender;
 float water;
 float hours;
 float drinks;
 float weigth;

 cout << "Please enter your gender.  M/F: ";
cin >> gender;

if (gender == "M" || gender == "m"){
float water = 0.68;
}
if (gender == "F" || gender == "f"){
float 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 weigths ";
 cin>> weigth;

// pure alcohol in gram / weigth * waterpercent

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



if (result <= 0.5|| 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;

}


i think the problem is this part here float g = weigth * water; // Weigth * water
if we take the weight and set to to lets say 60 and the the male water % that's 0.68 and * them then i should be 40,8 but in my program it ends out as something like "1.23535e-035" so something is clearly wrong

please help
water is uninitialized. On line 19 and 22 you create new float objects named water that you give values but these are different objects than the water created on line 10. Remove the float from line 19 and 22 and it should work better.
Topic archived. No new replies allowed.