Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 24th, 2004, 05:22 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
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 06:08 PM.

Reply With Quote
  #2  
Old September 24th, 2004, 07:54 PM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 8
There's a function named 'Power' in the Math unit.
Code:
function Power(const Base, Exponent: Extended): Extended;

Reply With Quote
  #3  
Old September 24th, 2004, 07:58 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
Thankyou...

Quote:
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.

Reply With Quote
  #4  
Old September 24th, 2004, 08:08 PM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 8
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)));

Reply With Quote
  #5  
Old September 24th, 2004, 08:48 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
Thankyou. I greatly appreciate your help in this matter!

Reply With Quote
  #6  
Old September 24th, 2004, 08:56 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
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?

Reply With Quote
  #7  
Old September 24th, 2004, 10:06 PM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 8
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)));

Reply With Quote
  #8  
Old September 24th, 2004, 10:10 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
Quote:
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.

Reply With Quote
  #9  
Old September 24th, 2004, 10:19 PM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 8
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.

Reply With Quote
  #10  
Old September 24th, 2004, 10:22 PM
host-solutions host-solutions is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Canada
Posts: 124 host-solutions User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 44 sec
Reputation Power: 5
Send a message via AIM to host-solutions Send a message via MSN to host-solutions
Quote:
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Newbie. Need help with calculator


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT