### Thread: Newbie. Need help with calculator

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14

#### Newbie. Need help with calculator

I am working on a calculator and need help. Can anyone here help me with coding a function to make a exponent.
I am using two edit boxes named one and two where one being base and two being the exponent. Their is only one calculation button!
By the way here is the code for the rest of the functions:
procedure TForm1.Button6Click(Sender: TObject);
begin
if RadioButton1.Checked = True then
answer.text := inttostr(strtoint(one.text)+ Strtoint(two.text))
else if RadioButton2.Checked = True then
answer.text := inttostr(strtoint(one.text) - Strtoint(two.text))
else if RadioButton3.Checked = True then
answer.text := inttostr(strtoint(one.text) * Strtoint(two.text))
else if RadioButton4.Checked = True then
answer.text := inttostr(strtoint(one.text) div Strtoint(two.text))

Thankyou!
Last edited by host-solutions; September 24th, 2004 at 06:08 PM.
2. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2004
Location
England
Posts
952
Rep Power
18
There's a function named 'Power' in the Math unit.
Code:
`function Power(const Base, Exponent: Extended): Extended;`
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14

#### Thankyou...

Originally Posted by rossM
There's a function named 'Power' in the Math unit.
Code:
`function Power(const Base, Exponent: Extended): Extended;`
Thankyou, I did not know there was a function that did that. Could you please explain how to implement it? I have just started about 1 week ago and I am not sure how to use this. I am also using delphi 1.
4. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2004
Location
England
Posts
952
Rep Power
18
Add 'Math' to the uses list at the top of your .pas file. This allows you to use the functions/procedures defined in that unit. Then add this piece of code to your button click procedure.
Code:
```  answer.Text := FloatToStr(Power(StrToFloat(one.Text),
StrToFloat(two.Text)));```
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14
Thankyou. I greatly appreciate your help in this matter!
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14
I keep getting:

Could you please tell me where I can find this file and where should I place it?
7. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2004
Location
England
Posts
952
Rep Power
18
If you don't have the Math unit there is an alternative way to do the calculation using functions from the System unit.
Code:
```answer.Text := FloatToStr(Exp(Ln(StrToFloat(one.Text))
* StrToFloat(two.Text)));```
8. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14
Originally Posted by rossM
If you don't have the Math unit there is an alternative way to do the calculation using functions from the System unit.
Code:
```answer.Text := FloatToStr(Exp(Ln(StrToFloat(one.Text))
* StrToFloat(two.Text)));```
Thankyou! It is working great!!!
If it is not too much trouble could you please explain what it is that you exactly did?
Last edited by host-solutions; September 24th, 2004 at 10:19 PM.
9. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Jan 2004
Location
England
Posts
952
Rep Power
18
Suppose x = base (text box one), y = exponent (text box two) and a = the answer you want. You can make a little equation that you can rearrange using laws of logarithms.
Code:
```x^y = a
Ln( x^y ) = Ln( a )
y * Ln( x ) = Ln( a )
Exp( y * Ln( x ) ) = a```
Exp (exponential) and Ln (natural log) functions are in the System unit, which means you don't need anything from the Math unit.
10. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2004
Location
Posts
124
Rep Power
14
Originally Posted by rossM
Suppose x = base (text box one), y = exponent (text box two) and a = the answer you want. You can make a little equation that you can rearrange using laws of logarithms.
Code:
```x^y = a
Ln( x^y ) = Ln( a )
y * Ln( x ) = Ln( a )
Exp( y * Ln( x ) ) = a```
Exp (exponential) and Ln (natural log) functions are in the System unit, which means you don't need anything from the Math unit.
Ah i see!!!!
Thankyou, I appreciate it!