Author |
Message |
xmdxtreme
![](http://www.battle.net/war3/images/nightelf/units/animations/demonhunter.gif)
|
Posted: 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 Rolling Eyes](http://compsci.ca/v3/images/smiles/icon_rolleyes.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Paul
![](http://i12.photobucket.com/albums/a207/paulbian/DDRDuck.png)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
xmdxtreme
![](http://www.battle.net/war3/images/nightelf/units/animations/demonhunter.gif)
|
Posted: Mon May 31, 2004 8:05 pm Post subject: (No subject) |
|
|
Thank you paul your always very helpful ![Laughing Laughing](http://compsci.ca/v3/images/smiles/icon_lol.gif) |
|
|
|
|
![](images/spacer.gif) |
xmdxtreme
![](http://www.battle.net/war3/images/nightelf/units/animations/demonhunter.gif)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
xmdxtreme
![](http://www.battle.net/war3/images/nightelf/units/animations/demonhunter.gif)
|
Posted: Mon May 31, 2004 9:46 pm Post subject: (No subject) |
|
|
bump |
|
|
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
xmdxtreme
![](http://www.battle.net/war3/images/nightelf/units/animations/demonhunter.gif)
|
Posted: Tue Jun 01, 2004 2:56 pm Post subject: (No subject) |
|
|
Edit:acctually ill use your code thank you! ![Laughing Laughing](http://compsci.ca/v3/images/smiles/icon_lol.gif) |
|
|
|
|
![](images/spacer.gif) |
|