Description: This program will perform simple bank functions based on the follow
ID: 653503 • Letter: D
Question
Description: This program will perform simple bank functions based on the following user input: '+': Add a deposit to the account balance. '-': Subtract a withdrawal from the account balance. '%': Add interest due to the account (interest is 1%) 'q' or 'Q': Quit the program. The program will be in a loop until user enters a 'q' or 'Q' character to quit the program. Verify withdrawal amount less than balance Write a C program to perform the above simple functions and output the corresponding results. Submittal and Grading: Correctness: Deposit, Withdrawal, Interest: Verifying withdrawal amount less than balance: Quit case: Program does not compile: Faulty error checking: No loop for continuous input: Good Structure and Documentation: Here is a sample output run:Explanation / Answer
#include <stdio.h>
void deposit()
{ int oldbalance;
int depositamout;
int result;
printf( "Deposit....." );
printf("Enter old balance: ");
scanf( "%d", &oldbalance );
printf("Enter deposit amount: ");
scanf( "%d", &depositamout);
printf("New balance is: %d " , (oldbalance+depositamout));
}
void withdraw()
{ int oldbalance;
int withdrawamout;
printf( "WithDrawl....." );
printf("Enter old balance: ");
scanf( "%d", &oldbalance );
printf("Enter deposit amount: ");
scanf( "%d", &withdrawamout);
if(withdrawamout>oldbalance){
printf("Please check your balance");
return;
}
printf("New balance is: %d ", (oldbalance+withdrawamout));
}
void interest()
{ int balance;
printf( "Interset...." );
printf("Enter balance: ");
scanf( "%d", &balance );
printf("New balance is: %f ", (balance*1.01));
}
int main()
{
char input;
char ans = 'Y';
while(ans == 'Y'||ans == 'y'){
printf( "Enter one of the following characters " );
printf( "'+': for a deposit " );
printf( "'-': for a withdrawl " );
printf( "'%': for adding interest " );
printf( "'q' or 'Q': Quit Program " );
input = getchar();
printf(input);
switch ( input ) {
case '+': /* Note the colon, not a semicolon */
deposit();
break;
case '-':
withdraw();
break;
case '%':
interest();
break;
case 'q':
printf( "Quiting.. " );
exit(0);
break;
case 'Q':
printf( "Quiting.. " );
exit(0);
break;
default:
printf( "Bad input, quitting! " );
return 0;
break;
}
printf(" YOU WANT TO CONTINUE (Y/N)");
scanf(" %c", &ans);
}
getchar();
}