Can anyone help me with this real# problem??
Author |
Message |
chrisc5553
|
Posted: Fri Oct 10, 2008 8:26 am Post subject: Can anyone help me with this real# problem?? |
|
|
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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
CodeMonkey2000
|
Posted: Fri Oct 10, 2008 9:57 am Post subject: RE:Can anyone help me with this real# problem?? |
|
|
Your program still crashes for negative integers. For real numbers you just ignore the decimal. and use strreal. |
|
|
|
|
 |
|
|