This code supposed to: 1 - take input balance on your bank atm 2 - identify credit or debit transaction 3 - Using switch case to perform bank transaction 4 - Display new balance
I have to change the scanf() function in line 9 to include the \n, the program does what it does even though I'm not sure if there is a better workaround. What can I do to improve my code in line 9?
#include <stdio.h>
int main()
{
float amt, debit, credit;
char acct;
printf("Enter initial amount:\n");
scanf("%f",&amt);
printf("Enter c for credit\n d for debit\n b for balance\n");
scanf ("\n%c",&acct);
switch(acct)
{
case 'c':
printf("Enter the credit amount:\n");
scanf("%f",&credit);
amt += credit;
printf("New amount=%f",amt);
break;
case 'd':
printf("Enter the debit amount:\n");
scanf("%f",&debit);
if(amt>=debit)
{
amt -= debit;
printf("New amount=%f",amt);
}
else
printf("insufficient amount\n");
break;
case 'b':
printf("Your balance is: %f",amt);
break;
default:
printf("invalid input");
break;
}
}