//*******************************************************
//
// Homework: 2
//
// Name: Naomi Jones
//
// Class: Survey, Summer 2025
//
// Date: June 3, 2025
//
// Description: Program which determines simple and
// compound interest.
//
//
//********************************************************
#include <stdio.h>
#include <math.h>
/* function prototypes */
float Calculate_Simple_Interest
(float principle
, float rate
, float time); float Calculate_Compound_Interest
(float principle
, float rate
, float time);
int main (void)
{
float simp_int; /* Simple interest earned over a period of time */
float comp_int; /* Compund interest earned over that period. */
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 ("\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 */
simp_int
= 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", simp_int
);
/*call compound interest function to calculate compound interest */
comp_int
= Calculate_Compound_Interest
(principle
, rate
, time);
/* print the compound interest earned to the screen */
printf ("\nThe total compound interest earned is: $%8.2f\n", comp_int
);
return 0; /* Indicate successful completion */
} /* end main */
/*****************************************************************
** Function: Calculate_Simple_Interest
**
** Description: Simple Interest is the amount of interest
** calculated by using the formula:
**
** interest = (principle * rate * time)
**
** 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. Example: 9.5% 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. */
/* TO DO: Step 1) Define a local variable of type float to hold interest */
/* ... Hint: This statement is the same of Step 1 in the challenge template */
float simp_int;
/* 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 */
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"); simp_int = 0;
}
else
{
/* calculate simple interest earned */
simp_int
= principle
* rate
* time; }
/* TO DO: Step 3) Add a return statement to return the interest to main */
/* ... Hint: This statement is the same of Step 3 in the challenge template */
return (simp_int);
} /* end Calculate_Simple_Interest */
/* Challenge: If you decide to do the challenge, you will need to add code */
/* for these two statements ... otherwise, just leave them as is */
/* Challenge TO DO: Step 1) Call Calculate_Compound_Interest */
/* function to calculate compound interest */
/* Challenge TO DO: Step 2) Print the compound interest to the screen */
/*****************************************************************
** 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) {
/* Challenge Step 1) define a local float variable for interest */
float comp_int;
/* Challenge TO DO: Step 2) Calculate compound interest earned */
/* by setting interest variable using formula above */
/* calculate compound interest earned */
comp_int
= (principle
* pow (1.0 + rate
, time)) - principle
;
/* Challenge Step 3) return interest to the calling function */
return (comp_int);
} /* end Calculate_Compound_Interest */