ITEC 120
Lab Quiz 1 - Blood Pressure solutions

10 pt solution

Here is a student solution that earned 10 pts. This is a very straightforward solution that doesn't even use an else.
It's a direct and correct translation of the english problem description into code. It's clear and it works.

 

if (systolic >= 140 || diastolic >= 90)
    S.o.p("\nYou have high blood pressure.");

if (systolic > 120 && systolic < 140 && diastolic < 90)
    S.o.p("\nYou have normal blood pressure, but it's a little high.");

if (diastolic > 80 && diastolic < 90 && systolic < 140)
    S.o.p("\nYou have normal blood pressure, but it's a little high.");

if (systolic > 90 && systolic <= 120 && diastolic > 60 && diastolic <= 80)
    S.o.p("\nYou have normal blood pressure.");

if (systolic <=90 || diastolic <= 60)
    S.o.p("\nYou have low blood pressure.");


11 pt solution

Here is a student solution that earned 11 pts. This solution took advantage of the else part of the if statement
to simplify logic. Redundant logic was removed, and we're left with a very concise solution that works.
Additionally, this student flagged negative numbers as invalid input.


if (top >= 140 || bottom >= 90)
{
    S.o.p("\nYou have high blood pressure. :(");
}
else if (top > 120 || bottom > 80)
{
    S.o.p("\nYou have normal blood pressure, but it's a little high.");
}
else if (top > 90 || bottom > 60)
{
    S.o.p("\nYour blood pressure reading is ideal.");
}
else if (top > 0 || bottom > 0)
{
    S.o.p("\nYou have low blood pressure.");
}
else
{
    S.o.p("\n***Invalid Input***");
}