Introduction: Sandbox Project: BAC Calculation and Interpretation
By Haarika Gogineni, Hana Schlosser, and Benedict Uiseco
In this project, we will attempt to calculate Blood Alcohol Concentration (BAC) based on a subject's number of drinks, weight, and gender. After outputting the calculated BAC, we will state the effects of that particular BAC level on the major organs and systems in the body and its physical attributes. We will also rearrange the BAC to calculate the number of hours for the subject to break down the alcohol and be completely sober.
Step 1: Identifying Number of Drinks (for-loop)
- Begin the code by using the "clear" and "clc" functions to clear the command window and workspace from previous work
- Use the "input" function to print to the command window, prompting the subject to enter the number of different drinks consumed.
- If the "NumberofDrinks" variable is greater than 1, use a "for loop" to prompt subject to enter the percent alcohol content and the ounces of alcohol in each type of drink. These variables are then used to calculate the total alcohol consumption by the subject.
Step 2: Define Other Variables (input, If/else)
- Use the "input" function again to prompt the subject to enter weight (lbs) and the number of hours elapsed since drinking; both factors affect the breakdown of alcohol in the blood.
- Use the "input" function to allow the subject to enter their gender.
- Supplement that function with an "if/elseif" statement assigning a specific constant to each gender. The "strcmp" function conpares the variable to the string, and if the variable entered is not 'male' or 'female' create an "else" statement that outputs ERROR.
Problem that we had: One of the problems that we had was when we tried to create a logical operator for the "gender" variable. The code would not function properly if we wrote "gender = 'male'" or "gender = 'female'"; it would revert to male regardless of whether that was the correct gender or not. The problem was that in "else" statements, it wasn't possible to have a variable equal to a string. As a result we had to revise the function to "strcmp" - the string-compare function - which allowed the code to progress.
Step 3: Define an Equation to Calculate BAC
- Use the formula found in research to develop an equation to find the BAC given the variables created in previous steps.
Step 4: Interpret the BAC Into Manifested Results on Human Body (if/elseif)
- Create an "if/elseif" statement that uses logistical operators (>,<,==,~, &) to display the corresponding resut according to the calculated BAC value that fits the chosen logistical statement.
- Use the "fprintf" function to print to the command window the BAC value and the resulting effects of that level on the body and their manifestations based on research.
- Continue to repeat these steps for all major ranges of BAC with varying effects
Step 5: Calculate the Number of Hours Before the Subject Is Sober
- Rearrange BAC Formula from Step 2 to find the number of hours until the subject is sober (BAC =0)
- Given that formula, calculate the number of hours and print this data to the command window using the "fprintf" function
Step 6: Results and Interpretation
- After writing the code and entering in values for the prompted questions, number of drinks, alcohol percentage, weight, gender, etc, click "Run" and obtain your results. The BAC will be shown along with a paragraph explaining the effects of the calculated BAC. Another printed statement will give you number of hours needed until you reach complete sobriety.
* NOTE: Since the interpretations paragraph is long, you will have to scroll to the right to read the entire message.