05-08-2006, 04:16 PM
Howdy all, I'm relatively new to QBasic and was wondering if I could get some assistance from those older and wiser in the ways of programming. Following is a program I wrote as an answer to a basic exercise. It is based on calculating the body mass index of an individual based on their input weight and height. There are several calculations towards the end of the program, including 'heighest weight entered'.
I was curious as to how I would go about figuring the lowest weight entered. I made several attempts at this and could not get it to work. Any ideas?
<PROGRAM STARTS HERE>
DIM personsHeight AS SINGLE
DIM personsWeight AS SINGLE
DIM bodyMassIndex AS SINGLE
DIM calculatedCounter AS INTEGER
DIM averageBodyMassIndex AS DOUBLE
DIM heighestWeight AS SINGLE
DIM totalBodyMassIndexes AS SINGLE
CLS
calculatedCounter = 0
totalBodyMassIndexes = 0
heighestWeight = 0
INPUT "Enter weight in kilos (0 to end) "; personsWeight
DO WHILE personsWeight <> 0
INPUT "Enter height in metres "; personsHeight
bodyMassIndex = personsWeight / (personsHeight * personsHeight)
IF bodyMassIndex < 20 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are underweight."
ELSEIF bodyMassIndex >= 20 AND bodyMassIndex <= 26 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You have a healthy weight."
ELSEIF bodyMassIndex > 26 AND bodyMassIndex <= 30 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are overweight."
ELSEIF bodyMassIndex > 30 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are obese."
END IF
calculatedCounter = calculatedCounter + 1
totalBodyMassIndexes = totalBodyMassIndexes + bodyMassIndex
averageBodyMassIndex = totalBodyMassIndexes / calculatedCounter
IF personsWeight > heighestWeight THEN
heighestWeight = personsWeight
END IF
INPUT "Enter weight in kilos (0 to end) "; personsWeight
LOOP
PRINT ""
PRINT "No. of BMIs calculated "; calculatedCounter
PRINT "Average BMI was "; averageBodyMassIndex
PRINT "Highest weight entered was "; heighestWeight
PRINT ""
END
I was curious as to how I would go about figuring the lowest weight entered. I made several attempts at this and could not get it to work. Any ideas?
<PROGRAM STARTS HERE>
DIM personsHeight AS SINGLE
DIM personsWeight AS SINGLE
DIM bodyMassIndex AS SINGLE
DIM calculatedCounter AS INTEGER
DIM averageBodyMassIndex AS DOUBLE
DIM heighestWeight AS SINGLE
DIM totalBodyMassIndexes AS SINGLE
CLS
calculatedCounter = 0
totalBodyMassIndexes = 0
heighestWeight = 0
INPUT "Enter weight in kilos (0 to end) "; personsWeight
DO WHILE personsWeight <> 0
INPUT "Enter height in metres "; personsHeight
bodyMassIndex = personsWeight / (personsHeight * personsHeight)
IF bodyMassIndex < 20 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are underweight."
ELSEIF bodyMassIndex >= 20 AND bodyMassIndex <= 26 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You have a healthy weight."
ELSEIF bodyMassIndex > 26 AND bodyMassIndex <= 30 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are overweight."
ELSEIF bodyMassIndex > 30 THEN
PRINT "Your BMI is "; bodyMassIndex
PRINT "You are obese."
END IF
calculatedCounter = calculatedCounter + 1
totalBodyMassIndexes = totalBodyMassIndexes + bodyMassIndex
averageBodyMassIndex = totalBodyMassIndexes / calculatedCounter
IF personsWeight > heighestWeight THEN
heighestWeight = personsWeight
END IF
INPUT "Enter weight in kilos (0 to end) "; personsWeight
LOOP
PRINT ""
PRINT "No. of BMIs calculated "; calculatedCounter
PRINT "Average BMI was "; averageBodyMassIndex
PRINT "Highest weight entered was "; heighestWeight
PRINT ""
END