formula into c#

Hello,

i am making a program in c#, and i like to get my formulas into the program but i dont know how , could any one help me
i upload my formulas there are four :

how can i write the formulas  in c# language

thank you
formule.png
kensy11Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TommySzalapskiCommented:
Is your log the natural log or log base 10? I'm guessing 10. It would look something like this:
Use Math.Pow(base, exponent) for power and Math.log10(number) for log.
For the nth root use
P = 100* (Pow( (Kn/K0), 1/N) - 1)
TommySzalapskiCommented:
Sorry. Should have been P = 100* (Math.Pow(Kn/K0, 1/N) - 1)

And
N = (Math.log10(Kn) - Math.log10(K0))/Math.log10(1+P/100)

The rest should be easy from there (my kid's crying).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kensy11Author Commented:
thanks but i get zero when i try it ? why ?


  class Berekening {
    public double BeginKapitaal( double k0, double kn, byte n) {

      double p;
      p = 100 * (Math.Pow(kn / k0, 1 / n) - 1);

      return p;
    
    }

Open in new window


RESULT
k0: 100000
kn : 200000
n : 15

Answer :  0


Could you please help me
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

TommySzalapskiCommented:
i would assume it's doing integer division. In most C languages when you divide an integer by another it gives an integer result so 1/n = 0. Try changing it to 1.0 / n
kensy11Author Commented:
ooh so when i want to divide an interger by for example 12 i should use   12.0 / n    right ?
kensy11Author Commented:
and for the first formula  i have got it like this, is it right ?


kn = k0 * (Math.Pow (1+ p/100))

Open in new window

kensy11Author Commented:
I think i fix it but i get this error message for the formula  n = Math.Log(kn) - Math.Log(k0)/ Math.Log(1+ p / 100);

Why ?



using System;

namespace MenuSamengesteldeIntrest {
  class Berekening {
    public double BeginKapitaal( double k0, double kn, byte n) {

      double p;
      
      p = 100 * (Math.Pow(kn / k0, 1.0 / n) - 1);
      kn = k0 * (Math.Pow(1 + p / 100, n));
      k0 = kn / ((Math.Pow(1 + p / 100, n)));
     
      n = Math.Log(kn) - Math.Log(k0)/ Math.Log(1+ p / 100);  // but for this line i get an error message " Error	1	Cannot implicitly convert type 'double' to 'byte'. An explicit conversion exists (are you missing a cast?) "
 "

      

      return p;
    
    }
  }/*Berekening*/
}/*MenuSamengesteldeIntrest*/

Open in new window

TommySzalapskiCommented:
Are you sure n should be a byte, not a double? That's why it's complaining.  The formula is going to generate a decimal number and possible a large one at that. A byte can only be an integer from 0 to 255.
kensy11Author Commented:
yes n should be byte,  is there a way to get around it ?

and are the formules right ?

      
      p = 100 * (Math.Pow(kn / k0, 1.0 / n) - 1);
      kn = k0 * (Math.Pow(1 + p / 100, n));
      k0 = kn / ((Math.Pow(1 + p / 100, n)));
      n = Math.Log(kn) - Math.Log(k0)/ Math.Log(1+ p / 100);

Open in new window


Thanks
TommySzalapskiCommented:
Yeah, you could cast it to a byte.
Try
n = Convert.ToByte(Math.Log(kn) - Math.Log(k0)/ Math.Log(1+ p / 100));

kensy11Author Commented:
thank you, the error about the type is gone but i have one other problem .

i guess i made a fault in converting  the formule into c# language .

System.OverflowException was unhandled
kensy11Author Commented:
it is fixed now the formula  should be

(Math.Log(kn) - Math.Log(k0)) / (Math.Log(1 + p / 100))

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.