|
|
@ -1,7 +1,7 @@ |
|
|
|
#include "interestCalculator.h" |
|
|
|
|
|
|
|
|
|
|
|
void calculateInterest(){ |
|
|
|
void calculateYearlyInterest(){ |
|
|
|
float principalAmount; |
|
|
|
float interestPerYear; |
|
|
|
float timeInYears; |
|
|
@ -29,17 +29,48 @@ void calculateInterest(){ |
|
|
|
float result= principalAmount*(1+(interestDecimal*timeInYears)); |
|
|
|
printf("\nAmount with the interest is %.2f.",result); |
|
|
|
} |
|
|
|
void calculateMonthlyInterest(){ |
|
|
|
float principalAmount; |
|
|
|
float interestPerMonth; |
|
|
|
float timeInMonths; |
|
|
|
|
|
|
|
printf("Please enter the principal amount:"); |
|
|
|
scanf("%f",&principalAmount); |
|
|
|
if(principalAmount<=0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
printf("\nPlease enter interest per month (percentage):"); |
|
|
|
scanf("%f",&interestPerMonth); |
|
|
|
if(interestPerMonth<=0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
printf("\nPlease enter interest time in months:"); |
|
|
|
scanf("%f",&timeInMonths); |
|
|
|
if(timeInMonths<=0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
float interestDecimal=interestPerMonth/100; |
|
|
|
|
|
|
|
float result= principalAmount*(1+(interestDecimal*timeInMonths)); |
|
|
|
printf("\nAmount with the interest is %.2f.",result); |
|
|
|
} |
|
|
|
|
|
|
|
void initiateCalculator(){ |
|
|
|
|
|
|
|
int input; |
|
|
|
char c; |
|
|
|
printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n"); |
|
|
|
printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n[2]Calculate monthly interest\n"); |
|
|
|
scanf("%d", &input); |
|
|
|
|
|
|
|
switch(input){ |
|
|
|
case 1: |
|
|
|
calculateInterest(); |
|
|
|
calculateYearlyInterest(); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
calculateMonthlyInterest(); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
@ -53,8 +84,8 @@ void initiateCalculator(){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int main(){ |
|
|
|
// int main(){ |
|
|
|
|
|
|
|
initiateCalculator(); |
|
|
|
// initiateCalculator(); |
|
|
|
|
|
|
|
} |
|
|
|
// } |