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



