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. /* 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. interest = principle * rate * time;
  42.  
  43. /* TO DO: Step 3) Add a return statement to return the interest to main */
  44. return interest;
  45.  
  46. } /* end Calculate_Simple_Interest */
  47.  
  48. float Calculate_Compound_Interest (float principle, float rate, float time)
  49. {
  50. /* Challenge Step 1) define a local float variable for interest */
  51. float interest;
  52.  
  53. /* Challenge TO DO: Step 2) Calculate compound interest earned */
  54. /* by setting interest variable using formula above */
  55. interest (principle * pow(1.0 + rate, time)) - principle;
  56.  
  57. /* Challenge Step 3) return interest to the calling function */
  58. return (interest);
  59.  
  60. } /* end Calculate_Compound_Interest */
  61.  
  62. int main (void)
  63. {
  64. float interest; /* The interest earned over a period of time */
  65. float principle; /* The amount being invested */
  66. float rate; /* The interest rate earned */
  67. float time; /* The years of the investment */
  68.  
  69. /* Initialize the interest value */
  70. interest = 0;
  71.  
  72. /* Enter values needed to determine interest */
  73. printf ("\nEnter your principle value: ");
  74. scanf ("%f", &principle);
  75.  
  76. printf ("\nEnter the rate: For example 9.5 percent would be .095: ");
  77. scanf ("%f", &rate);
  78.  
  79. printf ("\nEnter the period of time of your investment: :");
  80. scanf ("%f", &time);
  81.  
  82. /* Call simple interest function to calculate the simple interest */
  83. interest = Calculate_Simple_Interest (principle, rate, time);
  84.  
  85. /* Print the simple interest earned to the screen */
  86. printf ("\n\nThe total simple interest earned is: $%8.2f\n", interest);
  87.  
  88. /* Challenge TO DO: Step 1) Call Calculate_Compound_Interest function */
  89. /* to calculate the compound interest. */
  90.  
  91. interestCompound = Calculate_Compound_Interest(principle, rate, time);
  92.  
  93. /* Challenge TO DO: Step 2) Print the compound interest to the screen */
  94. printf("The total compound interest earned is: $%8.2f\n", interestCompound)
  95. return (0); /* indicate successful completion */
  96.  
  97. } /* end main */
  98.  
Compilation error #stdin compilation error #stdout 0.01s 5424KB
stdin
4500
0.095
6
compilation info
prog.c: In function ‘Calculate_Compound_Interest’:
prog.c:55:27: warning: implicit declaration of function ‘pow’ [-Wimplicit-function-declaration]
     interest (principle * pow(1.0 + rate, time)) - principle;
                           ^~~
prog.c:55:27: warning: incompatible implicit declaration of built-in function ‘pow’
prog.c:55:27: note: include ‘<math.h>’ or provide a declaration of ‘pow’
prog.c:2:1:
+#include <math.h>
 
prog.c:55:27:
     interest (principle * pow(1.0 + rate, time)) - principle;
                           ^~~
prog.c:55:5: error: called object ‘interest’ is not a function or function pointer
     interest (principle * pow(1.0 + rate, time)) - principle;
     ^~~~~~~~
prog.c:51:11: note: declared here
     float interest;
           ^~~~~~~~
prog.c: In function ‘main’:
prog.c:91:5: error: ‘interestCompound’ undeclared (first use in this function); did you mean ‘interest’?
     interestCompound = Calculate_Compound_Interest(principle, rate, time);
     ^~~~~~~~~~~~~~~~
     interest
prog.c:91:5: note: each undeclared identifier is reported only once for each function it appears in
prog.c:94:77: error: expected ‘;’ before ‘return’
  printf("The total compound interest earned is: $%8.2f\n", interestCompound)
                                                                             ^
                                                                             ;
     return (0); /* indicate successful completion */
     ~~~~~~                                                                   
prog.c:74:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &principle);
     ^~~~~~~~~~~~~~~~~~~~~~~~
prog.c:77:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &rate);
     ^~~~~~~~~~~~~~~~~~~
prog.c:80:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%f", &time);
     ^~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty