September 24th, 2004, 04:22 PM

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!
Please help!
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 hostsolutions; September 24th, 2004 at 05:08 PM.
September 24th, 2004, 06:54 PM

There's a function named 'Power' in the Math unit.
Code:
function Power(const Base, Exponent: Extended): Extended;
September 24th, 2004, 06:58 PM

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.
September 24th, 2004, 07:08 PM

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)));
September 24th, 2004, 07:48 PM

Thankyou. I greatly appreciate your help in this matter!
September 24th, 2004, 07:56 PM

I keep getting:
Error 15: File not found (MATH.DCU).
Could you please tell me where I can find this file and where should I place it?
September 24th, 2004, 09:06 PM

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)));
September 24th, 2004, 09:10 PM

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 hostsolutions; September 24th, 2004 at 09:19 PM.
September 24th, 2004, 09:19 PM

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.
September 24th, 2004, 09:22 PM

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!