Paste Search Dynamic
Recent pastes
P is the principle
1. /*******************************************************************************************************
2. Title: Calculate Simple Interest Example in C
3. Name: Ethan Alonso
4. Description:
5. This formula and example was taken from the about.com Mathematics web site, which
6. has lots of useful information and formulas.
7. The amount of interest can be calculated by using the formula: I = Prt
8. - where P is the principle, r is the rate, and t is the time of the investment
9. As an example, say we had to borrow or invest an amount of \$4500. The bank gives us
10. an interest rate of 9.5% over a period of 6 years. So, let's plug in the values, and we get:
11. I = (4500) (0.095) * (6)
12. I = \$2565.00
13. ***********************************************************************************************************/
14.
15. #include <stdio.h>
16. int main (void)
17. {
18.
19.     float interest;     /* The interest earned over a period of time */
20.     float principle;   /* The amount being invested */
21.     float rate;           /* The interest rate earned */
22.     float time;           /* The years of the investment */
23.
24.     /* Enter values needed to determine interest */
25.
26.     printf ("Enter your principle value: ");
27.     scanf ("%f", &principle);
28.     printf("\n");  /* new line */
29.
30.     printf ("Enter the rate: For example 9.5 percent would be .095: ");
31.     scanf ("%f", &rate);
32.     printf("\n");  /* new line */
33.
34.     printf ("Enter the period of time of your investment: ");
35.     scanf ("%f", &time);
36.     printf("\n");  /* new line */
37.
38.     /* If any value inputted is zero, then the interest is zero */
39.     if (principle == 0 || rate == 0 || time == 0)
40.     {
41.         printf("\nSince at least one of your values is zero, your interest will be zero\n");
42.         printf("... next time, make sure all values entered are non-zero!\n");
43.
44.         interest = 0;
45.     }
46.     else
47.     {
48.         /* calculate simple interest earned */
49.         interest = principle * rate * time;
50.     }
51.
52.     /* print the interest earned to the screen */
53.     printf("\n\nThe total interest earned is: \$%8.2f\n", interest);
54.
55.     return (0);  /* indicate successful completion */
56.
57. } /* end main */
58.
Parsed in 0.008 seconds