So i got an assignment to try and write a simple ATM program which shouldn't take long however ive hit a little snag... the problem that i am experiencing is when the program executes the if statement and i purposely enter a withdraw amount greater than 100 which i set when i select Y to go back to the main menu it goes back to the main however it then ends the program. This is my code below that i already started (feel free to critique :))...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int cash_withdrawls(w_amount);
int w_amount;
int c_bal = 100;
int main(void)
{
char selection;
printf("Welcome to BANK-AT-HOME's ATM System\n\n");
printf("Please select from the menu below\n");
printf("A. Cash Withdrawls\n");
printf("L. Lodgements\n");
printf("B. Balance Check\n");
printf("P. Bill Payment\n");
printf("C. Credit Purchase\n");
printf("E. Exit\n");
scanf("%c", &selection);
switch (selection) {
case 'A':
case 'a':
system("CLS");
cash_withdrawls() ;
break;
case 'L': ;
break;
case 'B': ;
break;
case 'P': ;
break;
case 'C': ;
break;
case 'E': ;
break;
default: printf("Select correct option...");
}
return c_bal;
}
int cash_withdrawls()
{
return_point: ;
char option;
printf("How much money do you with to withdraw from your account..?\n");
scanf("%d", &w_amount);
fflush(stdin);
if(w_amount > c_bal)
{
printf("Sorry you cannot withdraw %d, becuase you only have %d in your account...\n\n\n", w_amount ,c_bal);
printf("Press Y to return to main or N to try again...");
scanf("%c", &option);
if( option == 'Y' || option == 'y')
{
main();
}
else if(option == 'N' || option == 'n')
{
goto return_point;
}
}
else if (w_amount < c_bal)
{
printf("Do sumn! ! ! !\n\n");
}
return c_bal;
}
atn.jpg 260.67K
12 downloads