My first TCL Program

Was trying to figure out things with the Tool Command Language (TCL) for some time now. It’s pretty simple and organized!

 #! /usr/bin/tclsh
#This Program Calculates your BMI 
proc Bmi {a b} {
set a [expr {$a / 1.00}]; #so that integer value is converted to a float
set b [expr {$b / 1.00}]
set bmi [expr {($a) / ($b * $b)}]
return $bmi
}
puts -nonewline stdout "What is your weight in Kgs.?"
flush stdout
set x [gets stdin]; #gets the value from the user
puts -nonewline stdout "What is your height in metres?"
flush stdout
set y [gets stdin]
puts [format "Your BMI:%5.2f" [Bmi $x $y] ]

if { [Bmi $x $y] < 18.5} {puts stdout "You are Underweight"
} elseif { [Bmi $x $y] >= 18.5 && [Bmi $x $y] <=24.9} {puts stdout "You are Normal in weight"
} elseif { [Bmi $x $y] >= 25 && [Bmi $x $y] <=29.9} {puts stdout "You are Overweight"
} else {puts stdout "You are Obese!!!"} 

puts stdout "Please refer to the Table given below \
to know if you are healthy!! Stay Fit!!"
puts stdout "\nBMI\t\t\t\tWeight Status\n\
\nBelow 18.5\t\t\tUnderweight\n\
18.5-24.9\t\t\tNormal\n\
25-29.9\t\t\tOverweight\n\
30 & Above\t\t\tObese"

 

Advertisements
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: