17Blood Alcohol Calculator

Sometimes you have to perform a more complex calculation based on some provided inputs and then use that result to make a determination.

Create a program that prompts for your weight, gender, number of drinks, the amount of alcohol by volume of the drinks consumed, and the amount of time since your last drink. Calculate your blood alcohol content (BAC) using this formula

images/_pragprog/svg-0005.png

where

  • A is total alcohol consumed, in ounces (oz).

  • W is body weight in pounds.

  • r is the alcohol distribution ratio:

    • 0.73 for men

    • 0.66 for women

  • H is number of hours since the last drink.

Display whether or not it’s legal to drive by comparing the blood ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.