fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. /* These are function prototypes */
  5. float Calculate_Simple_Interest (float principle, float rate, float time);
  6. float Calculate_Compound_Interest (float principle, float rate, float time);
  7.  
  8. /*****************************************************************
  9. ** Function: Calculate_Simple_Interest
  10. **
  11. ** Description: Simple Interest is the amount of interest
  12. ** calculated by using the formula:
  13. **
  14. ** interest = (P * R * T)
  15. **
  16. ** where P is the principle, r is the rate, and t
  17. ** is the time of the investment
  18. **
  19. ** This function will return the simple interest
  20. ** calculated based upon it being passed the principle,
  21. ** rate, and time.
  22. **
  23. ** Parameters: Principle - The original principal to start with
  24. ** Rate - The rate of interest. If you wanted
  25. ** 9.5 percent it would be passed as 0.095
  26. ** Time - The time in years
  27. **
  28. ** Returns: Interest - The amount of simple interest earned
  29. **
  30. ********************************************************************/
  31.  
  32. float Calculate_Simple_Interest (float principle, float rate, float time)
  33. {
  34. /* You will only need to create three simple statements here ... */
  35. /* No other statements are needed. */
  36.  
  37. /* 1) TO DO: Step 1) Define local variable of type float to */
  38. /* hold the interest */
  39.  
  40. /* 2) TO DO: Step 2) Calculate simple interest earned - Determine the */
  41. /* interest using the values in the parameters: principle, rate, and */
  42. /* time ... and assign that value to the local variable you created */
  43. /* in Step 1 that holds the interest */
  44. /* .... Hint: This statement is right in the first homework */
  45.  
  46.  
  47. /* 3) TO DO: Step 3) Add a return statement to return the interest */
  48. /* calculated to main */
  49.  
  50. } /* end Calculate_Simple_Interest */
  51.  
  52. /*****************************************************************
  53. ** Function: Calculate_Compound_Interest
  54. **
  55. ** Description: Compound Interest is the amount of interest
  56. ** calculated by using the formula:
  57. **
  58. ** interest = (P * pow (1.0 + r, t)) - P
  59. **
  60. ** where P is the principle, r is the rate, and t
  61. ** is the time of the investment
  62. **
  63. ** This function will return the compound interest
  64. ** calculated based upon it being passed the principle,
  65. ** rate, and time.
  66. **
  67. ** Parameters: Principle - The original principal to start with
  68. ** Rate - The rate of interest. If you wanted
  69. ** 9.5 percent it would be passed as 0.095
  70. ** Time - The time in years
  71. **
  72. ** Returns: Interest - The amount of compound interest earned
  73. **
  74. ********************************************************************/
  75.  
  76. float Calculate_Compound_Interest (float principle, float rate, float time)
  77. {
  78. /* 1) define a local variable of type float to hold the interest */
  79. float interest;
  80. float rate;
  81. float time;
  82.  
  83. /* 2) TO DO: calculate compound interest earned ... */
  84. /* Set interest variable to the right formula value, see above */
  85.  
  86. /* 3) return the interest calculated back to the calling function */
  87. return (interest);
  88.  
  89. } /* end Calculate_Compound_Interest */
  90.  
  91. int main (void)
  92. {
  93. float interest; /* The interest earned over a period of time */
  94. float principle; /* The amount being invested */
  95. float rate; /* The interest rate earned */
  96. float time; /* The years of the investment */
  97.  
  98. /* Initialize the interest value */
  99. interest = 0;
  100.  
  101. /* Enter values needed to determine interest */
  102. printf ("\nEnter your principle value: ");
  103. scanf ("%f", &principle);
  104.  
  105. printf ("\nEnter the rate: For example 9.5 percent would be .095: ");
  106. scanf ("%f", &rate);
  107.  
  108. printf ("\nEnter the period of time of your investment: :");
  109. scanf ("%f", &time);
  110.  
  111. interest = Calculate_Simple_Interest (principle, rate, time);
  112.  
  113. /* print the simple interest earned to the screen */
  114. printf("\n\nThe total simple interest earned is: $%8.2f\n", interest);
  115.  
  116. /* Call the Calculate_Compound_Interest function and print that */
  117. /* interest here if you decide to do the challenge ... it is called */
  118. /* just like the Calculate_Simple_Interest function and printed */
  119. /* the same way. */
  120.  
  121. return (0); /* indicate successful completion */
  122.  
  123. } /* end main */
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4500 
0.095 
6 
compilation info
prog.c: In function ‘Calculate_Compound_Interest’:
prog.c:80:11: error: ‘rate’ redeclared as different kind of symbol
     float rate;
           ^~~~
prog.c:76:59: note: previous definition of ‘rate’ was here
 float Calculate_Compound_Interest (float principle, float rate, float time)
                                                     ~~~~~~^~~~
prog.c:81:11: error: ‘time’ redeclared as different kind of symbol
     float time;
           ^~~~
prog.c:76:71: note: previous definition of ‘time’ was here
 float Calculate_Compound_Interest (float principle, float rate, float time)
                                                                 ~~~~~~^~~~
prog.c:81:11: warning: unused variable ‘time’ [-Wunused-variable]
     float time;
           ^~~~
prog.c:80:11: warning: unused variable ‘rate’ [-Wunused-variable]
     float rate;
           ^~~~
prog.c: In function ‘Calculate_Simple_Interest’:
prog.c:50:1: warning: control reaches end of non-void function [-Wreturn-type]
 } /* end Calculate_Simple_Interest */
 ^
prog.c: In function ‘main’:
prog.c:103:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &principle);
     ^~~~~~~~~~~~~~~~~~~~~~~~
prog.c:106:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &rate);
     ^~~~~~~~~~~~~~~~~~~
prog.c:109:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &time);
     ^~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty