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

    Join Date
    Mar 2004
    Location
    Canada
    Posts
    124
    Rep Power
    11

    Exclamation 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 host-solutions; September 24th, 2004 at 05:08 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

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

    Join Date
    Mar 2004
    Location
    Canada
    Posts
    124
    Rep Power
    11

    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    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)));
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

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

    Join Date
    Mar 2004
    Location
    Canada
    Posts
    124
    Rep Power
    11
    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?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    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)));
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    Canada
    Posts
    124
    Rep Power
    11
    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 09:19 PM.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    England
    Posts
    952
    Rep Power
    14
    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.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    Canada
    Posts
    124
    Rep Power
    11
    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!

IMN logo majestic logo threadwatch logo seochat tools logo