ok I have been stuck on this for quite a while now
even when I try using math::pow it doesn't seem to work
well let me explain what i needed to do
i needed to create a simple interest and a compound interest calculator
i did the first part of it just fine
like so :
// Declare variables
double P, R, T, sum;
// Read in data
Double::TryParse(txtNum1->Text,P);
Double::TryParse(txtNum2->Text,R);
Double::TryParse(txtNum3->Text,T);
// Proccess data
sum = P * (1 + (T *(R/100)));
// Display results
txtBx4->Text = sum.ToString();
but when it comes to do the compound interest i need to work with powers of
and that seems to be the problem
heres what i need
// Declare variables
double P, R, T, sum;
// Read in data
Double::TryParse(txtNum1->Text,P);
Double::TryParse(txtNum2->Text,R);
Double::TryParse(txtNum3->Text,T);
// Proccess data
sum = P * (1 + (R/100)^to the power T
// Display results
txtBx5->Text = sum.ToString();
any help would be greatly appreciated thanks
and by the way am using visual studio if that helps any
Last edited on
say x=1+(R/100) then (1 + (R/100)^to the power T ==pow(x,T) //pow returns a double.
You will need a header file <cmath>.
I tried a header <math.h> but got a whole bunch of errors
I'm quite new to c++ can you be a little more specific please
What errors did you get? Not sure if this is what you want, but working with the GNU compiler the following code works:
#include<iostream>
#include<math.h>
using namespace std;
int main() {
double a = 2.0;
double b = 3.0;
double c;
c = pow(2.0,3.0);
cout<<c; //prints 8 to the standard output
}
So in your case the line: sum = P * (1 + (R/100^to the power T))
would be: sum = P * (1 + pow((R/100),T));
if you want T to be the exponent and (R/100) to be the base. Hope that helps.
EDIT: "using namespace std;" has nothing to do with the pow-function, it's just to make the name cout for standard output visible.
Last edited on