#include <stdio.h>
/*****************************************************************
** 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) {
// Step 1: Define a local variable to hold interest
float interest;
// Step 2: Calculate simple interest
interest
= principle
* rate
* time;
// Step 3: Return the interest
return interest;
} /* end Calculate_Simple_Interest */
/*****************************************************************
** Function: Calculate_Compound_Interest
**
** Description: Compound Interest is calculated by the formula:
**
** amount = principle * (1 + rate)^time
** compound_interest = amount - principle
**
** Parameters: Principle - The original principal to start with
** Rate - The rate of interest (e.g. 0.095 for 9.5%)
** Time - The time in years
**
** Returns: Compound Interest earned
********************************************************************/
float Calculate_Compound_Interest
(float principle
, float rate
, float time) {
float amount
= principle
* pow(1 + rate
, time); return amount - principle;
}
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: :");
/* Call simple interest function to calculate the simple interest */
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
);
/* Challenge TO DO: Step 1) Call Calculate_Compound_Interest function */
/* to calculate the compound interest. */
/* Challenge TO DO: Step 2) Print the compound interest to the screen */
return (0); /* indicate successful completion */
} /* end main */