
-----------------------------------
xmdxtreme
Mon May 31, 2004 7:37 pm

doller decimal ?
-----------------------------------
like you know how a atm machine works like when you type the amount to withdraw it will fill up the decimal places then the rest like if you typr 23 then it shows .23 or like 4555 it shows 45.55 or 544432 it shows 5444.32 then after that process it has to be a real number not string what should i do? :roll:

-----------------------------------
Paul
Mon May 31, 2004 7:53 pm


-----------------------------------

var word : string := ""
var num : real
var pos : int
var key : string (1)
put "Enter ur amount: " ..
loop

    getch (key)
    if ord (key) = 10 then
        exit
    end if
    word += key
    pos := index (word, ".")
    if length (word) >= 2 then
        if pos not= 0 then
            word := word (1 .. (pos - 1)) + word ((pos + 1) .. *)
        end if
        word := word (1 .. * -2) + "." + word (* -1 .. *)
    end if
    cls
    put word
end loop
put "Here is your amount"
num := strreal (word)
put "$", num



-----------------------------------
xmdxtreme
Mon May 31, 2004 8:05 pm


-----------------------------------
Thank you paul your always very helpful  :lol:

-----------------------------------
xmdxtreme
Mon May 31, 2004 8:13 pm


-----------------------------------
hm still stuck now my code is messy.

var word : string := "" 
var num : real 
var pos : int 
var key : string (1) 

loop

put "Enter ur amount: " .. 
    getch (key) 
    exit when ord (key) = 10
    
    if ord (key) >= 48 and ord (key) = 2 then 
        if pos not= 0 then 
            word := word (1 .. (pos - 1)) + word ((pos + 1) .. *) 
        end if 
        word := word (1 .. * -2) + "." + word (* -1 .. *) 
    end if 
    cls
    put word
    end if 
end loop 
put "Here is your amount" 
num := strreal (word) 
put "$", num


-----------------------------------
xmdxtreme
Mon May 31, 2004 9:46 pm


-----------------------------------
bump

-----------------------------------
beard0
Mon May 31, 2004 10:36 pm


-----------------------------------
The code looked quite complex, so I tried doing the same thing, starting fresh. Try this:
var num : real
var st : string := ""
var key : string (1)

put "Enter amount:"
put "$0.00" ..
loop
    getch (key)
    if strintok (key) then
        st += key
    end if
    exit when key = chr (10)
    num := strint (st) / 100
    locate (2, 1)
    put "$", num : 0 : 2
    locate (2, length (intstr (round (num))) + 5)
end loop
locate (3, 1)
put "Here is your amount"
put "$", num : 0 : 2


-----------------------------------
xmdxtreme
Tue Jun 01, 2004 2:56 pm


-----------------------------------
Edit:acctually ill use your code thank you! :lol:
