fork download
  1. #include <stdio.h>
  2.  
  3. /*****************************************************************
  4. ** Function: Calculate_Simple_Interest
  5. **
  6. ** Description: Simple Interest is the amount of interest
  7. ** calculated by using the formula:
  8. **
  9. ** interest = (P * R * T)
  10. **
  11. ** where P is the principle, r is the rate, and t
  12. ** is the time of the investment
  13. **
  14. ** This function will return the simple interest
  15. ** calculated based upon it being passed the principle,
  16. ** rate, and time.
  17. **
  18. ** Parameters: Principle - The original principal to start with
  19. ** Rate - The rate of interest. If you wanted
  20. ** 9.5 percent it would be passed as 0.095
  21. ** Time - The time in years
  22. **
  23. ** Returns: Interest - The amount of simple interest earned
  24. **
  25. ********************************************************************/
  26.  
  27. float Calculate_Simple_Interest (float principle, float rate, float time)
  28. {
  29.  
  30. /* You will only need to create three simple statements here ... */
  31. /* No other statements are needed. */
  32.  
  33. /* TO DO: Step 1) Define local variable of type float to hold interest */
  34. float interest;
  35.  
  36.  
  37. /* TO DO: Step 2) Calculate simple interest earned. Determine interest */
  38. /* using the values in the parameters: principle, rate, and time .... */
  39. /* and assign that value to the local variable you created in step 1 */
  40. /* that holds the interest */
  41. /* .... Hint: This statement is right in the first homework */
  42. interest = principle * rate * time;
  43.  
  44.  
  45. /* TO DO: Step 3) Add a return statement to return the interest to main */
  46. return (interest);
  47.  
  48.  
  49. } /* end Calculate_Simple_Interest */
  50.  
  51. int main (void)
  52. {
  53. float interest; /* The interest earned over a period of time */
  54. float principle; /* The amount being invested */
  55. float rate; /* The interest rate earned */
  56. float time; /* The years of the investment */
  57.  
  58. /* Initialize the interest value */
  59. interest = 0;
  60.  
  61. /* Enter values needed to determine interest */
  62. printf ("\nEnter your principle value: ");
  63. scanf ("%f", &principle);
  64.  
  65. printf ("\nEnter the rate: For example 9.5 percent would be .095: ");
  66. scanf ("%f", &rate);
  67.  
  68. printf ("\nEnter the period of time of your investment: :");
  69. scanf ("%f", &time);
  70.  
  71. /* Call simple interest function to calculate the simple interest */
  72. interest = Calculate_Simple_Interest (principle, rate, time);
  73.  
  74. /* Print the simple interest earned to the screen */
  75. printf ("\n\nThe total simple interest earned is: $%8.2f\n", interest);
  76.  
  77. /* Challenge TO DO: Step 1) Call Calculate_Compound_Interest function */
  78. /* to calculate the compound interest. */
  79.  
  80. /* Challenge TO DO: Step 2) Print the compound interest to the screen */
  81.  
  82. return (0); /* indicate successful completion */
  83.  
  84. } /* end main */
  85.  
Success #stdin #stdout 0s 5284KB
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 simple interest earned is: $ 2565.00