Browse Source

Hotfix: resolve file name problem (2/2)

remotes/origin/feature/balance-operations
fdlt3817 2 years ago
parent
commit
cf87508c6b
  1. 4
      src/currentCustomerAccountBalance.h
  2. 4
      src/depositMoney.c
  3. 125
      src/sendMoney.c
  4. 14
      src/sendMoney.h
  5. 4
      src/updateCustomerAccountBalance.h
  6. 8
      src/withdrawMoney.c

4
src/currentCustomerAccountBalance.h

@ -1,5 +1,5 @@
#ifndef CURRENTCUSTOMERACCOUNTBALANCE_H_
#define CURRENTCUSTOMERACCOUNTBALANCE_H_
#ifndef CurrentCustomerAccountBalance_H
#define CurrentCustomerAccountBalance_H
#include <stdio.h>

4
src/depositMoney.c

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

125
src/sendMoney.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;
}

14
src/sendMoney.h

@ -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

4
src/updateCustomerAccountBalance.h

@ -1,5 +1,5 @@
#ifndef UPDATECUSTOMERACCOUNTBALANCE_H_
#define UPDATECUSTOMERACCOUNTBALANCE_H_
#ifndef UpdateCustomerAccountBalance_H
#define UpdateCustomerAccountBalance_H
#include <stdio.h>
#include <stdbool.h>

8
src/withdrawMoney.c

@ -1,6 +1,7 @@
#include "withdrawMoney.h"
#include "updateCustomerAccountBalance.c"
#include "currentCustomerAccountBalance.c"
#include "updateCustomerAccountBalance.h"
#include "currentCustomerAccountBalance.h"
void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) {
char c;
@ -51,12 +52,11 @@ bool withdraw(int user_id) {
updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance);
if( updateSuccess ) {
notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id);
return true;
}
else {
printf("Some error occured! Sorry for the inconvenience caused.\n");
return false;
}
return updateSuccess;
}
else {

Loading…
Cancel
Save