Sunday, August 2, 2009

What is missing from this c program. please help me.... thanks?

The simple interest on a loan is calculated by the formula


interest = principal * rate * days / 365;


The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.








#include%26lt;iostream.h%26gt;


#include %26lt;stdio.h%26gt;


int main(void)





{


int principal, rate, days, interest;


printf("enter principal\n");


scanf("%d", %26amp;principal);


printf(" enter rate\n");


scanf("%d", %26amp;rate);


printf(" enter days ");


scanf("%d", days);


interest = principal * rate * days / 365;


printf(" the interest is %d");





system("pause");


return 0;





}

What is missing from this c program. please help me.... thanks?
No %26amp; in front of days in scanf





interest should probably not be integer in real life because of div by 365.
Reply:The corrected version.





#include %26lt;stdio.h%26gt;


int main(void)


{


double principal, rate, interest;


int days;


printf("enter principal $");


scanf("%lf", %26amp;principal);


printf(" enter rate :");


scanf("%lf", %26amp;rate);


printf(" enter days ");


scanf("%d", %26amp;days);


interest = principal * rate * days / 365.0;


printf(" the interest is %f", interest);


printf("Press Enter%26gt;");


fflush(stdin);


getchar();


return 0;


}


No comments:

Post a Comment