fork download
  1. /*******************************************************************************************************
  2.  
  3. Title: Calculate Simple Interest Example in C
  4.  
  5. Name: Emmanuel Nwankwo
  6.  
  7. Description:
  8.  
  9. This formula and example was taken from the about.com Mathematics web site, which
  10. has lots of useful information and formulas.
  11.  
  12. URL: http://m...content-available-to-author-only...t.com/od/businessmath/ss/Interest.htm
  13.  
  14. The amount of interest can be calculated by using the formula: I = Prt
  15.  
  16. - where P is the principle, r is the rate, and t is the time of the investment
  17.  
  18. As an example, say we had to borrow or invest an amount of $4500. The bank gives us
  19. an interest rate of 9.5% over a period of 6 years. So, let's plug in the values, and we get:
  20.  
  21. I = (4500) (0.095) * (6)
  22.  
  23. I = $2565.00
  24.  
  25. ***********************************************************************************************************/
  26.  
  27. #include <stdio.h>
  28. int main (void)
  29. {
  30.  
  31. float interest; /* The interest earned over a period of time */
  32. float principle; /* The amount being invested */
  33. float rate; /* The interest rate earned */
  34. float time; /* The years of the investment */
  35.  
  36. /* Enter values needed to determine interest */
  37.  
  38. printf ("Enter your principle value: ");
  39. scanf ("%f", &principle);
  40. printf("\n"); /* new line */
  41.  
  42. printf ("Enter the rate: For example 9.5 percent would be .095: ");
  43. scanf ("%f", &rate);
  44. printf("\n"); /* new line */
  45.  
  46. printf ("Enter the period of time of your investment: ");
  47. scanf ("%f", &time);
  48. printf("\n"); /* new line */
  49.  
  50. /* If any value inputted is zero, then the interest is zero */
  51. if (principle == 0 || rate == 0 || time == 0)
  52. {
  53. printf("\nSince at least one of your values is zero, your interest will be zero\n");
  54. printf("... next time, make sure all values entered are non-zero!\n");
  55.  
  56. interest = 0;
  57. }
  58. else
  59. {
  60. /* calculate simple interest earned */
  61. interest = principle * rate * time;
  62. }
  63.  
  64. /* print the interest earned to the screen */
  65. printf("\n\nThe total interest earned is: $%8.2f\n", interest);
  66.  
  67. return (0); /* indicate successful completion */
  68.  
  69. } /* end main */
Success #stdin #stdout 0s 9432KB
stdin
4500
0.095
6
stdout
Enter your principle value: 
Enter the rate: For example 9.5 percent would be .095: 
Enter the period of time of your investment: 


The total interest earned is: $ 2565.00