Newer
Older
C1201227-SATO / bmi.rb
@sato sei sato sei on 23 Dec 2021 1 KB Create bmi.rb
#!/usr/bin/env ruby
# coding: utf-8

require 'cgi'
c = CGI.new(:accept_charset => "UTF-8")
print "Content-type: text/html; charset=UTF-8\n\n"

name = c["name"]
var7 = c{"age1"}
var8 = c{"age2"}
var9 = c{"age3"}
var1 = c["height1"]
var2 = c["height2"]
var3 = c["height3"]
var4 = c["weight1"]
var5 = c["weight2"]
var6 = c["weight3"]

height = (100 * var1.to_f + 10 * var2.to_f + var3.to_f) / 100
weight = (100 * var4.to_f + 10 * var5.to_f + var6.to_f)

bmi = weight / (height ** 2)
1goodwei = height ** 2 * 22
2goodwei = height ** 2 * 21.5

print"<html>
<head><title>BMI値</title></head>
<body>\n"

print"<h1>#{name}さんのBMI値</h1>\n"

print"<p>身長:#{height}m</p>\n"
print"<p>体重:#{weight}kg</p>\n"
printf("<p>BMI:%3.1f (理想は女性:21.5、男性:22)</p>\n",bmi)
printf("<p>適正体重は%4.1fkgです(男性の場合)。</p>\n",height ** 2 * 22)
printf("<p>適正体重との比較は%±4.1fです。</p>\n"1goodwei - weight)
printf("<p>適正体重は%±4.1fkgです(女性の場合)。</p>\n",height ** 2 * 21.5)
printf("<p>適正体重との比較は%4.1fです。</p>\n"2goodwei - weight)
print"</body>\n"
print"</html>\n"