Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- const double safe = 0.00;
- const double someImpairment = 0.04;
- const double significantAffected = 0.08;
- const double someCriminalPenalties = 0.10;
- const double deathPossible = 0.30;
- const string SAFE = "Safe To Drive";
- const string SOMEIMPAIR = "Some Impairment";
- const string SIGNIFICANT = "Driving Skills Significantly Affected";
- const string MOST_STATES = "Criminal Penalties in Most US States";
- const string ALL_STATES = "Legally Intoxicated - Criminal Penalties in All US States";
- const string YOURE_DEAD = "Death is Possible!";
- void computeBloodAlcoholConcentration(int numDrinks, int weight, int duration, double &maleBAC, double &femaleBAC)
- {
- double maleBAC_CONSTANT = 3.8;
- double femaleBAC_CONSTANT = 4.5;
- maleBAC = (((double)numDrinks / (double)weight) * maleBAC_CONSTANT - (((double)duration / 40) * 0.01));
- femaleBAC = (((double)numDrinks / (double)weight) * femaleBAC_CONSTANT - (((double)duration / 40) * 0.01));
- if (maleBAC < 0)
- maleBAC = 0;
- if (femaleBAC < 0)
- femaleBAC = 0;
- }
- string impairment(double bac)
- {
- double BAC = bac;
- if (BAC <= safe)
- return SAFE;
- else if (BAC < someImpairment)
- return SOMEIMPAIR;
- else if (BAC < significantAffected)
- return SIGNIFICANT;
- else if (BAC < someCriminalPenalties)
- return MOST_STATES;
- else if (BAC <= deathPossible)
- return ALL_STATES;
- else
- return YOURE_DEAD;
- }
- int promptForInteger(string const &message, int lower, int upper)
- {
- int x;
- cout << endl << message << endl;
- cout << "Lower?" << endl;
- cin >> lower;
- cout << "Upper?" << endl;
- cin >> upper;
- do
- {
- cout << "Enter a number within range: ";
- cin >> x;
- } while(x < lower || x > upper);
- return x;
- }
- char promptForMorF(string const &message)
- {
- char gender;
- cout << message << endl;
- do
- {
- cout << "M/F?" << endl;
- cin >> gender;
- } while(gender != 'M' && gender != 'F');
- return gender;
- }
- int main()
- {
- double genderconstant, maleBAC = 0, femaleBAC = 0, bac;
- int numDrinks, weight, duration;
- string message;
- cout << "Number of drinks?" << endl;
- cin >> numDrinks;
- cout << "Weight in pounds?" << endl;
- cin >> weight;
- cout << "Duration in minutes?" << endl;
- cin >> duration;
- // cout << "Gender? M/F" << endl;
- // cin >> gender;
- // if (gender == 'M' || gender == 'm')
- // femaleBAC = 0;
- // else
- // maleBAC = 0;
- computeBloodAlcoholConcentration(numDrinks, weight, duration, maleBAC, femaleBAC);
- cout << "Male BAC is " << maleBAC << endl;
- cout << "Female BAC is " << femaleBAC << endl;
- bac = maleBAC;
- promptForInteger(impairment(bac), 0, 0);
- promptForMorF(impairment(bac));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement