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