Hi guys new here ^.^ I'm working out some examples from C Primer Plus, Fifth Edition By Stephen Prata and I stumbled upon the following example.
I have managed to do simple and compound interest. But can't seem to do the last part. All help is appreciated.
John invests 200 dollars at 15% simple interest. (That is, every year, the investment earns an interest equal to 15% of the original investment.) Luke invests 200 dollars at 10% interest compounded annually. (That is, interest is 10% of the current balance, including previous addition of interest.) Write a program that finds how many years it takes for luke's invested sum to overtake John's along with a display showing the two values at that time.
Code:
#include<math.h>
int main()
{
float p,q,r,SI,CI;
int n;
printf("Enter the value of Principal p = ");
scanf("%f",&p);
printf("Enter the value of Rate r = ");
scanf("%f",&r);
printf("Enter the value of Period in year n = ");
scanf("%d",&n);
SI = ((p*r*n)/100);
printf("Simple Interest SI=%f \n",SI);
q = 1+(r/100);
CI=p*pow(q,n)-p;
printf("Compound Interest CI=%f \n",CI);
return 0;
}
Thanks