Advertisement
ninepintcoggie

Untitled

Feb 25th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. const double safe = 0.00;
  8. const double someImpairment = 0.04;
  9. const double significantAffected = 0.08;
  10. const double someCriminalPenalties = 0.10;
  11. const double deathPossible = 0.30;
  12. const string SAFE = "Safe To Drive";
  13. const string SOMEIMPAIR = "Some Impairment";
  14. const string SIGNIFICANT = "Driving Skills Significantly Affected";
  15. const string MOST_STATES = "Criminal Penalties in Most US States";
  16. const string ALL_STATES = "Legally Intoxicated - Criminal Penalties in All US States";
  17. const string YOURE_DEAD = "Death is Possible!";
  18.  
  19. void computeBloodAlcoholConcentration(int numDrinks, int weight, int duration, double &maleBAC, double &femaleBAC)
  20. {
  21. double maleBAC_CONSTANT = 3.8;
  22. double femaleBAC_CONSTANT = 4.5;
  23. maleBAC = (((double)numDrinks / (double)weight) * maleBAC_CONSTANT - (((double)duration / 40) * 0.01));
  24. femaleBAC = (((double)numDrinks / (double)weight) * femaleBAC_CONSTANT - (((double)duration / 40) * 0.01));
  25. if (maleBAC < 0)
  26. maleBAC = 0;
  27. if (femaleBAC < 0)
  28. femaleBAC = 0;
  29. }
  30.  
  31. string impairment(double bac)
  32. {
  33. double BAC = bac;
  34. if (BAC <= safe)
  35. return SAFE;
  36. else if (BAC < someImpairment)
  37. return SOMEIMPAIR;
  38. else if (BAC < significantAffected)
  39. return SIGNIFICANT;
  40. else if (BAC < someCriminalPenalties)
  41. return MOST_STATES;
  42. else if (BAC <= deathPossible)
  43. return ALL_STATES;
  44. else
  45. return YOURE_DEAD;
  46. }
  47.  
  48. int promptForInteger(string const &message, int lower, int upper)
  49. {
  50. int x;
  51. cout << endl << message << endl;
  52.  
  53. cout << "Lower?" << endl;
  54. cin >> lower;
  55. cout << "Upper?" << endl;
  56. cin >> upper;
  57. do
  58. {
  59. cout << "Enter a number within range: ";
  60. cin >> x;
  61. } while(x < lower || x > upper);
  62. return x;
  63. }
  64.  
  65. char promptForMorF(string const &message)
  66. {
  67. char gender;
  68. cout << message << endl;
  69. do
  70. {
  71. cout << "M/F?" << endl;
  72. cin >> gender;
  73. } while(gender != 'M' && gender != 'F');
  74. return gender;
  75. }
  76.  
  77. int main()
  78. {
  79. double genderconstant, maleBAC = 0, femaleBAC = 0, bac;
  80. int numDrinks, weight, duration;
  81. string message;
  82. cout << "Number of drinks?" << endl;
  83. cin >> numDrinks;
  84. cout << "Weight in pounds?" << endl;
  85. cin >> weight;
  86. cout << "Duration in minutes?" << endl;
  87. cin >> duration;
  88. // cout << "Gender? M/F" << endl;
  89. // cin >> gender;
  90. // if (gender == 'M' || gender == 'm')
  91. // femaleBAC = 0;
  92. // else
  93. // maleBAC = 0;
  94. computeBloodAlcoholConcentration(numDrinks, weight, duration, maleBAC, femaleBAC);
  95. cout << "Male BAC is " << maleBAC << endl;
  96. cout << "Female BAC is " << femaleBAC << endl;
  97. bac = maleBAC;
  98. promptForInteger(impairment(bac), 0, 0);
  99. promptForMorF(impairment(bac));
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement