Here is the program that i got for getting integer, but im hving trouble with changing it to get Real number.
Turing: |
function getInteger : int
const ENTER : char := chr (10) % Constant ASCII code for the Enter Key
var ch : string (1) := 'x'
var number : int := 0
var digits : int := 0
var negative : boolean := false
put "Please enter a Integer : " ..
loop
if hasch then
getch (ch )
if negative = true then
number := - 1 * strint(ch ) + number * 10
digits := digits + 1
elsif negative = false then
if ch >= '0' and ch <= '9' then
number := number * 10 + strint (ch )
digits := digits + 1
elsif ch = '-' and digits = 0 then
negative := true
digits := digits + 1
elsif ch not= ENTER then
digits := 0
number := 0
cls
put "** Invalid Entry Attempted**"
put "Please enter any Integer: " ..
end if
elsif ch not= ENTER then
digits := 0
number := 0
cls
put "** Invalid Entry Attempted**"
put "Please enter any Integer: " ..
end if
end if
exit when ch = chr (10) or digits >= 9
end loop result number
end getInteger
% Test Main
var num : int
num := getInteger
put ""
put "You entered ", num, " as your number" |
Mod Edit: Code Tags! Last warning. |