Author |
Message |
Kharybdis
|
Posted: Thu Oct 11, 2007 7:58 pm Post subject: How do you reverse numbers? |
|
|
k... this problem is really bugging me.... ive tried to do it for like 3 hrs and i just cant get it to work.
The problem is to get a real number in the range 0 to 1 that contains 3 decimals. Then you reverse the number and display the sum.
Ex. user enters 0.934 and the program adds 0.439 to 0.934
anyone help? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HeavenAgain
|
Posted: Thu Oct 11, 2007 8:47 pm Post subject: RE:How do you reverse numbers? |
|
|
Snip! We don't just provide answers here.
any shorter way? turing = |
|
|
|
|
|
Clayton
|
Posted: Thu Oct 11, 2007 8:53 pm Post subject: RE:How do you reverse numbers? |
|
|
I suggest you try looking into realstr(), strreal(), and string manipulation |
|
|
|
|
|
Tony
|
Posted: Thu Oct 11, 2007 9:23 pm Post subject: RE:How do you reverse numbers? |
|
|
as Clayton points out, working with characters is easier. Though Mathematically, you could also use powers of 10 and floor() function to get individual digits. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kharybdis
|
Posted: Fri Oct 12, 2007 5:48 am Post subject: Re: How do you reverse numbers? |
|
|
String manipulation... i wish i could just do this :
var num,num1 : real
var ans1,ans2,ans3: string
floor(num)
num(3)= ans1
num(4) = ans2
num(5) = ans3
put floor(num) +ans1+ans2+ans3
num1 := floor(num) +ans1+ans2+ans3 (combine those statements not add....)
lol
lots of wrong there.....but that my was my original idea proved wrong. |
|
|
|
|
|
Saad
|
Posted: Fri Oct 12, 2007 5:53 am Post subject: RE:How do you reverse numbers? |
|
|
Well why are you flooring the number as it gets rid of the number? because its between 0-1 which results as 0 |
|
|
|
|
|
Kharybdis
|
Posted: Fri Oct 12, 2007 6:50 am Post subject: Re: How do you reverse numbers? |
|
|
Im flooring num. I WANT it to always be zero.
like floor(num)+"." plus ans1 plus ans2 plus ans3. |
|
|
|
|
|
Tony
|
Posted: Fri Oct 12, 2007 12:33 pm Post subject: Re: RE:How do you reverse numbers? |
|
|
Actually you're not too far off.
We could probably assume that floor(num) will always be 0. Or rather "0".
And + does join, not add strings.
Clayton @ Thu Oct 11, 2007 8:53 pm wrote: I suggest you try looking into realstr(), strreal()
or intstr() and strint(). Depends on if you get a hold of digits before or after you convert everything into a string. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Kharybdis
|
Posted: Sat Oct 13, 2007 2:54 pm Post subject: Re: How do you reverse numbers? |
|
|
i got it like the day after i posted this ....
final answer is..
var num : string
var num1, number : string
put "Please enter a number in the range of 0 to 1. Must contain 3 decimals."
get num
num1 := num (5) + num (4) + num (3)
number := "0." + num1
put "The sum of your number, and its reverse is ", strreal (number) + strreal (num)
lol took me 3 hrs to figure out a 3 minute typed code.
Its not error trapped or proofed or anything like that. If you enter 0.2341 or 0.12 it crashes. or even 1.242 |
|
|
|
|
|
Tony
|
Posted: Sat Oct 13, 2007 3:10 pm Post subject: Re: How do you reverse numbers? |
|
|
Kharybdis @ Sat Oct 13, 2007 2:54 pm wrote: lol took me 3 hrs to figure out a 3 minute typed code.
Heh, it actually should be this way. If you figure something out in 3 minutes, but it takes your 3 hours to type it up -- you're doing something very very wrong (and I did see this happen). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kharybdis
|
Posted: Sat Oct 13, 2007 5:00 pm Post subject: Re: How do you reverse numbers? |
|
|
Its not necessarily that case. What if you were given a project to do with a concept idea, but even though the idea is very simple, it takes a lot of time to actually make it work. Still, i basically agree with ya. |
|
|
|
|
|
|