// John Bent's CS 110 Hand-out 1
// Blood Alcohol Content calculator, Original
//
// a simple c++ program to calculate BAC using Widmark's formula
// program limitations - can only calculate for one proof of
// liquor at a time - (i.e. cannot calculate BAC for a person
// who has drank more than one proof of liquor and no error checking for user input
#include //allows use of cout & cin
#include //allows input & output of external files
//declare global variables
const float MALE_RATE = 0.68, FEMALE_RATE = 0.55;
//portion of body weight which holds alcohol
//usually constants are defined like this
int main ()
{
//variables to be input and modified
ifstream infile ("BAC_data.dat", ios::in);
//associates infile w/ BAC_data.dat
char gender;
int weight;
float widmark_rate, oz_drunk, proof, BAC, time,
denominator, numerator, metabolized,
blood_gravity, metabolism, oz_to_pound;
// get info from the user now
cout << "Are you a an or a oman?" << endl << " :";
cin >> gender;
cout << "\nWhat is your weight in pounds?" << endl << " :";
cin >> weight;
cout << "\nHow many ounces of alcohol did you drink?" << endl << " :";
cin >> oz_drunk;
cout << "\nWhat was the proof of the alcohol?" << endl << " :";
cin >> proof;
cout << "\nHow many hours have passed since your first drink?"
<< endl << " :";
cin >> time;
// input constants from input file
infile >> blood_gravity >> metabolism >> oz_to_pound;
// the program now has the information needed to calculate
if (gender == 'm' || gender == 'M') widmark_rate = MALE_RATE;
else widmark_rate = FEMALE_RATE;
numerator = oz_drunk * proof * oz_to_pound * blood_gravity;
denominator = weight * widmark_rate;
metabolized = time * metabolism;
BAC = numerator/denominator - metabolized;
// this is a little redundant for the sake of simplicity
if (BAC < 0) BAC = 0; // can't metabolize to negative
// the program can now output the result
cout << endl << endl << endl; // skip some spaces
cout << "Your BAC after drinking " << oz_drunk
<< " ounces of " << proof << " proof liquor over a "
<< time << " hour span is: " << endl << endl << " : "
<< BAC << " BAC." <