fdlt3817
2 years ago
6 changed files with 149 additions and 10 deletions
-
4src/currentCustomerAccountBalance.h
-
4src/depositMoney.c
-
125src/sendMoney.c
-
14src/sendMoney.h
-
4src/updateCustomerAccountBalance.h
-
8src/withdrawMoney.c
@ -0,0 +1,125 @@ |
|||
#include "sendMoney.h" |
|||
#include "depositMoney.h" |
|||
#include "withdrawMoney.h" |
|||
#include "currencyExchange.h" |
|||
#include "currentCustomerAccountBalance.h" |
|||
#include "updateCustomerAccountBalance.h" |
|||
|
|||
|
|||
|
|||
void showBalance(int customerID){ |
|||
float balance=getAvailableAccountBalance(customerID); |
|||
printf("\n:.:.:.:.:.:"); |
|||
printf("\nYour current balance is %.2f.\n",balance); |
|||
printf(":.:.:.:.:.:\n"); |
|||
} |
|||
|
|||
float askToConvert(float input, int customerID){ |
|||
char c; |
|||
char symbol[]=""; |
|||
int id; |
|||
float converted; |
|||
printf("\nWould you like to convert the amount from € to another currency?[y] yes [any] no\n"); |
|||
scanf(" %c",&c); |
|||
if(c=='y'||c=='Y'){ |
|||
printf("\nPlease select from one of the following currencties to convert to:"); |
|||
printf("\n[1] USD"); |
|||
printf("\n[2] GBP"); |
|||
printf("\n[3] YEN"); |
|||
printf("\n[4] YUAN\n"); |
|||
scanf("%d",&id); |
|||
|
|||
if(id>0&&id<5){ |
|||
converted=convert(input,id); |
|||
}else{ |
|||
return 0; |
|||
} |
|||
switch(id){ |
|||
case 1: |
|||
symbol[0]='$'; |
|||
break; |
|||
case 2: |
|||
symbol[0]='P'; |
|||
break; |
|||
case 3: |
|||
symbol[0]='Y'; |
|||
break; |
|||
case 4: |
|||
symbol[0]='X'; |
|||
break; |
|||
} |
|||
printf("\nYou have successfuly transfered %.2f%s to [%d]",converted, symbol,customerID); |
|||
return converted; |
|||
}else{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
void askToShowBalance(int customerID){ |
|||
char c; |
|||
printf("\nWould you like to see your remaining balance? [y] yes [any] no\n"); |
|||
scanf(" %c",&c); |
|||
if(c=='y' || c=='Y'){ |
|||
showBalance(customerID); |
|||
} |
|||
return; |
|||
} |
|||
|
|||
bool sendMoney(int customerID){ |
|||
float availableAccountBalance=getAvailableAccountBalance(customerID); |
|||
float amountToSend; |
|||
int recID; |
|||
|
|||
showBalance(customerID); |
|||
printf("\nHow much would you like to send?\n"); |
|||
scanf("%f",&amountToSend); |
|||
if(amountToSend>0 && amountToSend<availableAccountBalance){ |
|||
printf("\nYour input was %.2f€. Please enter the recipient id.\n",amountToSend); |
|||
scanf("%d",&recID); |
|||
if(recID>1000){ |
|||
bool recExists=checkCustomerExists(recID); |
|||
if(recExists){ |
|||
if(recID==customerID){ |
|||
printf("\nYou cannot send money to yourself. Aborting. \n"); |
|||
return false; |
|||
} |
|||
else{ |
|||
if(withdrawSpecificAmount(customerID, amountToSend)){ |
|||
if(depositSpecificAmount(recID, amountToSend)){ |
|||
askToConvert(amountToSend, recID); |
|||
//printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID); |
|||
askToShowBalance(customerID); |
|||
return true; |
|||
} |
|||
else{ |
|||
printf("\nSomething went wrong with the transfer. Please contact staff."); |
|||
} |
|||
} |
|||
} |
|||
|
|||
}else{ |
|||
printf("\nThis ID is not from a customer of our bank. A transfer fee of %.2f€ will be taken.\n", TRANSFER_FEE); |
|||
if(withdrawSpecificAmount(customerID, amountToSend+TRANSFER_FEE)){ |
|||
askToConvert(amountToSend, recID); |
|||
//printf("\nYou have successfuly transfered %.2f€ to [%d]\n",amountToSend,recID); |
|||
askToShowBalance(customerID); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
printf("\nThe ID you have entered is not valid. Aborting. \n"); |
|||
} |
|||
|
|||
}else{ |
|||
//error |
|||
return false; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
int main(){ |
|||
sendMoney(1234); |
|||
return 0; |
|||
} |
@ -0,0 +1,14 @@ |
|||
#ifndef SENDMONEY_H |
|||
#define SENDMONEY_H |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
#define TRANSFER_FEE 0.8 |
|||
void showBalance(int customerID); |
|||
float askToConvert(float input, int customerID); |
|||
void askToShowBalance(int customerID); |
|||
bool sendMoney(int customerID); |
|||
|
|||
#endif // SENDMONEY_H |
Write
Preview
Loading…
Cancel
Save
Reference in new issue