Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 doller decimal ?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xmdxtreme




PostPosted: Mon May 31, 2004 7:37 pm   Post subject: 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? Rolling Eyes
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Mon May 31, 2004 7:53 pm   Post subject: (No subject)

code:

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




PostPosted: Mon May 31, 2004 8:05 pm   Post subject: (No subject)

Thank you paul your always very helpful Laughing
xmdxtreme




PostPosted: Mon May 31, 2004 8:13 pm   Post subject: (No subject)

hm still stuck now my code is messy.
code:

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) <= 57 then
    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 if
end loop
put "Here is your amount"
num := strreal (word)
put "$", num
xmdxtreme




PostPosted: Mon May 31, 2004 9:46 pm   Post subject: (No subject)

bump
beard0




PostPosted: Mon May 31, 2004 10:36 pm   Post subject: (No subject)

The code looked quite complex, so I tried doing the same thing, starting fresh. Try this:
code:
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




PostPosted: Tue Jun 01, 2004 2:56 pm   Post subject: (No subject)

Edit:acctually ill use your code thank you! Laughing
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: