Hers the the problem that i got for get postive integers, and i want to change it to get intger, so it can hv negative number
Turing: |
function getPositiveInteger : 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
put "Please enter a positive Integer : " ..
loop
if hasch then
getch (ch )
if ch >= '0' and ch <= '9' then
number := number * 10 + strint (ch )
digits := digits + 1
elsif ch not= ENTER then
digits := 0
number := 0
cls
put "** Invalid Entry Attempted**"
put "Please enter an Integer greater than or equal to zero: " ..
end if
end if
exit when ch = chr (10) or digits >= 9
end loop
result number
end getPositiveInteger
% Test Main
var num : int
num := getPositiveInteger
put ""
put "You entered ", num, " as your number"
|
|