## math

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Klaus
Posts: 10910
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

Hm, you could try this:

Code: Select all

``````...
put fld "input" into age -- contains the age in years
put 67 - age into Y
## To see if it is really anumber
ANSWER Y
put max(1,Y) into x
...``````
Running out of ideas now...

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

I now got to a conclusion that the problem is the subtracting the age from 67,
somebody has an alternate way to do that?

Klaus, tried what you suggested, no luck.

Klaus
Posts: 10910
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

What exactly does "no luck" mean?
Did you see the answer dialog?
If yes, what did it tell you?

I created the same szenario, field "input", field "output" and a button with this script:

Code: Select all

``````on mouseUp
put fld "input" into age -- contains the age in years
put max(1,67-age) into x -- avoid division by zero
put 1000000 into v -- the target amount
put 0.1 into r -- the interest rate 10% of one = 0.1
put yearlyAmount(x,r,v) into fld "output"
end mouseUp

function yearlyAmount x,r,v
put v/((((1+r)^x)-1)/r) into ann
return format("%.2f",ann) -- cash format = two digits
end yearlyAmount``````
I entered a number into fld "input" and got a valid result in fld "output".
So the script is definitvely OK and the problem must be somewhere else!

SparkOut
Posts: 1918
Joined: Sun Sep 23, 2007 4:58 pm

### Re: math

I think the value in the variable named age must nor be valid. ("age" isn't a reserved word, is it? I don't think so.)
Try

Code: Select all

``````put field "input" into tAge
if tAge is a number then
put 67 - tAge into Y
put max (1,Y) into X
else
answer "tAge is not a valid number and contains" && tAge
end if``````
I am going to guess that field "input" LOOKS like it contains a number, but it also has a return character after it. That would make it a string which can't be subtracted from a number. Try clearing the field, set its "tabOnReturn" property true and that should prevent the issue if this is the correct guess. Above all, data entry validation is at the heart of it.

Klaus
Posts: 10910
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

I already suggested this, and according to Aviv, everything is OK!?

SparkOut
Posts: 1918
Joined: Sun Sep 23, 2007 4:58 pm

### Re: math

I don't see where he's confirmed that the value in the field is not taking extra empty lines / cr through to the variable value. He just said "no luck" but I still suspect that the issue is with a blank line/ cr in the input field .

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

### Re: math

Hi can't understand the forumal, the first form was:

The second form is:

Is this the formula?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 10910
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

SparkOut wrote:
Wed Sep 05, 2018 10:56 pm
I don't see where he's confirmed that the value in the field is not taking extra empty lines / cr through to the variable value. He just said "no luck" but I still suspect that the issue is with a blank line/ cr in the input field.
So do I, but finally I decided to believe him, must be my good education...

Klaus
Posts: 10910
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: math

Buongiorno Max,
MaxV wrote:
Thu Sep 06, 2018 10:01 am
Hi can't understand the forumal, the first form was:

The second form is:

Is this the formula?
I think Hermann is the only person who really knows.

Best

Klaus (Claudio Maggiore)

bogs
Posts: 3273
Joined: Sat Feb 25, 2017 10:45 pm

### Re: math

I'm no -hh (by any stretch of the imagination), but let us see if we can help you out breaking down the formula by explaining percentages as digits since the 10% is all that really changed for the 2 formulas, so I'll refer you to this page which makes it pretty easy and painless to understand.

Here is the quote pertaining to your question though -
Explanation:
To convert from percents to decimals, you divide the percent by 100, which gives you decimal equivalent of the percent.
So, if you have 10%, and you want to express that as a decimal (which is what you need to do the calculation), you do this -

Code: Select all

``10 / 100 = .1``
Go ahead, pull out the calculator, and enter it just that way, and you'll see it pop up .1, and if you reverse it, you'll get 10 back again.

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

Hi all,
thank you for your help, you're the best!
I finally figured this out, couldn't do it without you!
hope you all having a great day <3 , if not hope it'll get better ASAP.

thanks again,
Aviv

capellan
Posts: 607
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

### Re: math

Hi Avivchen,

Which was the error? A comma? A return? Parentheses?
Thanks in advance!

Al

avivchen64
Posts: 8
Joined: Thu Aug 30, 2018 8:51 am

### Re: math

actually there were 2 problems, the first one was the subtraction problem,
I couldn't do it, the max(67-age) didn't work for me... the code with tAge worked for me.
the second prob was the fact that failed tries I did still were written in the input field.

have a great day!
Aviv