Browse Source

Implement enter month option to interestCalculator

remotes/origin/feature/balance-operations
fdlt3817 2 years ago
parent
commit
dd623e4219
  1. 4
      src/depositMoney.c
  2. 27
      src/interestCalculator.c

4
src/depositMoney.c

@ -1,6 +1,6 @@
#include "depositMoney.h"
#include "updateCustomerAccountBalance.h"
#include "currentCustomerAccountBalance.h"
#include "updateCustomerAccountBalance.c"
#include "currentCustomerAccountBalance.c"
void askToTryAgain(bool afterError, int customerID){
char choice;

27
src/interestCalculator.c

@ -14,6 +14,9 @@ void troubleshoot(int errorCode){
case 2:
printf("Duration not valid. Make sure it is a valid number over the value of zero.");
break;
case 3:
printf("Invalid option. Aborting.");
break;
}
}
@ -25,6 +28,7 @@ void calculateYearlyInterest(){
float principalAmount;
float interestPerYear;
float timeInYears;
int choice;
printf("Please enter the principal amount:");
if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) {
@ -37,13 +41,28 @@ void calculateYearlyInterest(){
troubleshoot(0);
return;
}
printf("\nPlease enter interest time in years:");
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) {
printf("\nWould you like to enter the time in [1]months or in [2]years?\n");
scanf("%d",&choice);
if(choice==1){
printf("\nPlease enter interest time in months:");
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) {
troubleshoot(2);
return;
}
timeInYears=timeInYears/12;
}else if(choice==2){
printf("\nPlease enter interest time in years:");
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) {
troubleshoot(2);
return;
}
}else{
troubleshoot(2);
return;
}
float interestDecimal=interestPerYear/100;
float result= initiateInterest(principalAmount,interestDecimal,timeInYears);

Loading…
Cancel
Save