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 | /* Title: Calculate Simple Interest Example in C Name: Matthew Sutton Description: This formula and example was taken from the about.com Mathematics web site, which has lots of useful information and formulas. URL: http://math.about.com/od/businessmath/ss/Interest.htm The amount of interest can be calculated by using the formula: I = Prt - where P is the principle, r is the rate, and t is the time of the investment As an example, say we had to borrow or invest an amount of $4500. The bank gives us an interest rate of 9.5% over a period of 6 years. So, let's plug in the values, and we get: I = (4500) (0.095) * (6) I = $2565.00 */ #include <stdio.h> 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 */ /* If any value inputted is zero, then the interest is zero */ if (principle == 0 || rate == 0 || time == 0) { printf("\nSince at least one of your values is zero, your interest will be zero\n"); printf("... next time, make sure all values entered are non-zero!\n"); interest = 0; } else { /* calculate simple interest earned */ 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.02s memory: 1724 kB returned value: 0
28000 .069 15
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: $28980.00
-
result: Success time: 0.01s memory: 1724 kB returned value: 0
500000 .0389 30
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: $583499.99
-
result: Success time: 0.02s memory: 1724 kB returned value: 0
350000 .0385 30
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: $404250.00
-
result: Success time: 0.01s memory: 1724 kB returned value: 0
10500 .035 10
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: $ 3675.00
-
result: Success time: 0.01s 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



