CLS
REM Declare Varibles
DIM MILES, YARDS, FEET, INCHES AS DOUBLE
DIM KM, METER, TINCH AS DOUBLE
DIM CM, TMETER AS DOUBLE
REM INPUT THE DATA
INPUT "ENTER THE DISTANCE IN MILES", MILES
INPUT "ENTER THE DISTANCE IN YARDS", YARDS
INPUT "ENTER THE DISTANCE IN FEET", FEET
INPUT "ENTER THE DISTANCE IN INCHES", INCHES
REM CONVERT INTO TOTAL INCHES
TINCH = 63360 * MILES + 36 * YARDS + 12 * FEET + INCHES
REM CONVERT INTO TOTAL METER
TMETER = TINCH / 39.37
REM CONVERT TO KILOMETER
KM = INT(TMETER / 1000)
REM CONVERT TO METER
METER = INT(TMETER - KM * 1000)
REM CONVERT TO CENTIMETER
CM = (TMETER - (KM * 1000) - METER) * 100
REM PRINT DETAILS
PRINT "KILOMETER", KM
PRINT "METER", METER
PRINT "CENTIMETER", CM;
经典 QBasic 没有 round 函数,所以你需要自带。
FUNCTION round# (num AS DOUBLE, dp AS INTEGER)
'WARNING: USE "#" at the end of constant values,
'or else you will get rounding errors:
' "num = .45" >> "num = .449999988079071
' "num = .45#" >> "num = .45"
DIM exp1 AS LONG, num2 AS LONG
exp1 = 10 ^ dp: num2 = num * exp1: round# = num2 / exp1
PRINT num
END FUNCTION
借来的,qbasicnews.com
如果我没记错的话,你可以使用 PRINT USING 语句。
cm_number = 73.53315
PRINT USING "##.##"; cm_number
OUTPUT: 73.53
"#" - 代表数字, "." - 表示小数点位置
单击此处查看更详细的说明。