#include <stdio.h>
#include <math.h>
/* These are function prototypes */
float Calculate_Simple_Interest
(float principle
, float rate
, float time); float Calculate_Compound_Interest
(float principle
, float rate
, float time);
/*****************************************************************
** Function: Calculate_Simple_Interest
**
** Description: Simple Interest is the amount of interest
** calculated by using the formula:
**
** interest = (P * R * T)
**
** 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 upon 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 0.095
** Time - The time in years
**
** Returns: Interest - The amount of simple interest earned
**
********************************************************************/
float Calculate_Simple_Interest
(float principle
, float rate
, float time) {
/* You will only need to create three simple statements here ... */
/* No other statements are needed. */
/* 1) TO DO: Step 1) Define local variable of type float to */
/* hold the interest */
float interest;
/* 2) TO DO: Step 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 */
interest
= principle
* rate
* time;
/* 3) TO DO: Step 3) Add a return statement to return the interest */
/* calculated to main */
return (interest);
} /* end Calculate_Simple_Interest */
/*****************************************************************
** Function: Calculate_Compound_Interest
**
** Description: Compound Interest is the amount of interest
** calculated by using the formula:
**
** interest = (P * pow (1.0 + r, t)) - P
**
** where P is the principle, r is the rate, and t
** is the time of the investment
**
** This function will return the compound interest
** calculated based upon 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 0.095
** Time - The time in years
**
** Returns: Interest - The amount of compound interest earned
**
********************************************************************/
float Calculate_Compound_Interest
(float principle
, float rate
, float time) {
/* 1) define a local variable of type float to hold the interest */
float interest;
/* 2) TO DO: calculate compound interest earned ... */
/* Set interest variable to the right formula value, see above */
interest
= (principle
* powf
(1.0f + rate
, time)) - principle
;
/* 3) return the interest calculated back to the calling function */
return (interest);
} /* end Calculate_Compound_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 */
/* Initialize the interest value */
interest = 0;
/* Enter values needed to determine interest */
printf ("\nEnter your principle value: "); scanf ("%f", &principle
);
printf ("\nEnter the rate: For example 9.5 percent would be .095: ");
printf ("\nEnter the period of time of your investment: :");
interest
= Calculate_Simple_Interest
(principle
, rate
, time);
/* print the simple interest earned to the screen */
printf("\n\nThe total simple interest earned is: $%8.2f\n", interest
);
/* Call the Calculate_Compound_Interest function and print that */
/* interest here if you decide to do the challenge ... it is called */
/* just like the Calculate_Simple_Interest function and printed */
/* the same way. */
interest
= Calculate_Compound_Interest
(principle
, rate
, time); printf("\n\nThe total compound interest earned is: $%8.2f\n", interest
);
return (0); /* indicate successful completion */
} /* end main */