Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Lowest Number Input
#1
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
Reply
#2
you could do something like this:


at the top of your program, declarew a variable called lowestWeight.

when you're setting variables to 0, set lowest weight to something rediculous like 999999

now, just reverse your highest weight check

If personsWeight < lowestWeight Then
lowestWeight = personsWeight
End If
Reply
#3
Don't wait around for a "Thank you" from Amy. I thing he/she is one of those discourtious people who post on 10 forums and take the answer and run without responding, so the thread stays open forever. :-(

Here was the post on The QBasic Forum:
http://www.network54.com/Forum/13959/message/1147086177

My final response there
> Looks like it will "do it" to me

had this code:

CLS
INPUT "Enter weight in kilos (0 to end) "; personsWeight
IF personsWeight = 0 THEN PRINT "No data entered": SYSTEM
highestWeight = personsWeight
lowestWeight = personsWeight
DO WHILE personsWeight <> 0

Note: No need to assume a lowest weight such as 9999 (which I also suggested in an earlier response). This will work even if the weights entered are 99999 and 99998. LOL.

In general, when searching for highest/lowest, just use the first value entered as both. That is easy because the first value entered is normally outside of the DO loop anyway.

Mac
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)