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.  
  35.  
  36. /* TO DO: Step 2) Calculate simple interest earned. Determine interest */
  37. /* using the values in the parameters: principle, rate, and time .... */
  38. /* and assign that value to the local variable you created in step 1 */
  39. /* that holds the interest */
  40. /* .... Hint: This statement is right in the first homework */
  41.  
  42.  
  43. /* TO DO: Step 3) Add a return statement to return the interest to main */
  44.  
  45.  
  46. } /* end Calculate_Simple_Interest */
  47.  
  48. int main (void)
  49. {
  50. float interest; /* The interest earned over a period of time */
  51. float principle; /* The amount being invested */
  52. float rate; /* The interest rate earned */
  53. float time; /* The years of the investment */
  54.  
  55. /* Initialize the interest value */
  56. interest = 0;
  57.  
  58. /* Enter values needed to determine interest */
  59. printf ("\nEnter your principle value: ");
  60. scanf ("%f", &principle);
  61.  
  62. printf ("\nEnter the rate: For example 9.5 percent would be .095: ");
  63. scanf ("%f", &rate);
  64.  
  65. printf ("\nEnter the period of time of your investment: :");
  66. scanf ("%f", &time);
  67.  
  68. /* Call simple interest function to calculate the simple interest */
  69. interest = Calculate_Simple_Interest (principle, rate, time);
  70.  
  71. /* Print the simple interest earned to the screen */
  72. printf ("\n\nThe total simple interest earned is: $%8.2f\n", interest);
  73.  
  74. /* Challenge TO DO: Step 1) Call Calculate_Compound_Interest function */
  75. /* to calculate the compound interest. */
  76.  
  77. /* Challenge TO DO: Step 2) Print the compound interest to the screen */
  78.  
  79. return (0); /* indicate successful completion */
  80.  
  81. } /* end main */
  82.  
Success #stdin #stdout 0s 5304KB
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: $    0.00