Page 433 - Computer Software Application TP - Volume 1
P. 433
COMPUTER SOFTWARE APPLICATION - CITS
Step 2: Type the following Sub Procedure and save it in a macro enabled work book
Sub Calculate_BMI()
Dim weight As Double
Dim height As Double
Dim bmi As Double
Dim result As String
‘ Prompt user to enter weight in kilograms
weight = InputBox(“Enter your weight in kilograms:”)
‘ Prompt user to enter height in meters
height = InputBox(“Enter your height in meters:”)
‘ Check if weight and height are greater than 0
If weight > 0 And height > 0 Then
‘ Calculate BMI using the formula: weight / (height * height)
bmi = weight / (height * height)
‘ Determine the BMI category
If bmi< 18.5 Then
result = “Underweight”
ElseIfbmi>= 18.5 And bmi< 25 Then
result = “Normal weight”
ElseIfbmi>= 25 And bmi< 30 Then
result = “Overweight”
Else
result = “Obese”
End If
‘ Display the calculated BMI and category
MsgBox “Your BMI is: “ &Round(bmi, 2) &vbCrLf& “BMI Category: “ & result
418
CITS : IT & ITES - Computer Software Application - Exercise 70