Write a complete C program that functions as a bank account
Solution
#include <stdio.h>
int main(){
float balance;
float annualPercentageRate;
int day,month,year;
printf(\"Enter the following details:\ \");
printf(\"Starting balance: \");
scanf(\"%f\",&balance);
printf(\"Annual Percentage Rate: \");
scanf(\"%f\",&annualPercentageRate);
printf(\"Date in format DD/MM/YYYY: \");
scanf(\"%d/%d/%d\",&day,&month,&year);
FILE* fid = fopen(\"xactlog.txt\",\"w\");
fprintf( fid, \"Starting Balance: %f\ \", balance);
fprintf( fid, \"Annual Percentage Rate: %f\ \", annualPercentageRate);
fprintf( fid, \"Date: %d/%d/%d\ \", day, month, year );
char action;
scanf(\"%c\",&action);
while(1){
printf(\"Select an option:\ D for making a deposit, W for withdrawing from the account, \");
printf(\"I for displaying Interest Rate Earned, F for applying a fee and C for closing the account\ \");
scanf(\"%c\", &action );
if( action == \'D\' ){
float deposit;
printf(\"Enter the amount to deposit: \");
scanf(\"%f\",&deposit);
balance += deposit;
fprintf(fid, \"Deposit %f in the account : Success\ \", deposit);
}
else if( action == \'W\' ){
float withdrawl;
printf(\"Enter the amount you want to withdraw: \");
scanf(\"%f\",&withdrawl);
if( balance < withdrawl ){
printf(\"Can\'t do the transaction due to insufficient balance\ \");
fprintf(fid, \"Withdrawing %f from the account: Failed\ \", withdrawl);
}
else{
balance -= withdrawl;
fprintf(fid, \"Withdrawing %f from the account: Success\ \", withdrawl);
}
}
else if( action == \'I\' ){
balance += balance*(annualPercentageRate/100);
fprintf(fid, \"Adding %f interest to the account: Success\ \", balance*annualPercentageRate);
}
else if( action == \'F\' ){
float fee;
printf(\"Enter the fee amount: \");
scanf(\"%f\",&fee);
balance -= fee;
fprintf(fid, \"Applied %f fee to the account: Success\ \", fee);
}
else if( action == \'C\' ){
printf(\"Enter the closing date in format DD/MM/YYYY\ \");
scanf(\"%d/%d/%d\", &day,&month,&year);
fprintf(fid, \"Closing Date: %d/%d/%d\ \", day, month, year );
fprintf(fid, \"Closing Balance: %f\ \", balance );
fprintf(fid, \"Thank you for your business\ \");
break;
}
scanf(\"%c\", &action );
}
fclose(fid);
return 0;
}

