I'm using a switch for an ATM machine program. Every time I select an option for my switch it just reprints the menu. Did I mess something up within the cases? I've also tried putting case '1': and so on which did not work either.
Code:
#include <stdio.h>
int main()
{
int balance, pin, tempPin, choice, choice2, choice3=0;
char ans;
printf("Please enter a pin:\n");
printf("The beginning number must not start with 0\n");
scanf("%d", &tempPin);
if(tempPin < 1000){
printf("Invalid Pin");
return 0;
}
printf("Would you like a receipt?\n");
printf("y or Y -> Yes\n");
printf("n or N-> No\n");
scanf("%c\n", &ans);
do{
system("cls\n");
printf("Choose from the following:\n");
printf("1- Fast Cash\n");
printf("2- Withdraw\n");
printf("3- Deposit\n");
printf("4- Check Balance\n");
printf("5- Get Card Back\n");
scanf("%c\n", &choice);
switch (choice){
case 1:
printf("Fast Cash: Select from the following\n");
printf("1-- $20.00 2-- $40.00\n");
printf("3-- $80.00 4-- $100.00\n");
scanf("%c", &choice2);
switch(choice2){
case '1':
balance-=20;
case '2':
balance-=40;
case '3':
balance-=80;
case '4':
balance-=100;
}
printf("1- Another Transaction 2- Get Card Back\n");
scanf("%d\n", &choice3);
if(choice3 == 2){
printf("Please take your card.\n");
break;
}
case 2:
system("cls\n");
int amtWithdraw;
printf("Enter an amount (enter 0 to cancel):");
scanf("%d", &amtWithdraw);
balance-=amtWithdraw;
printf("1- Another Transaction 2- Get Card Back\n");
scanf("%d\n", &choice3);
if(choice3 == 2){
printf("Please take your card.\n");
break;
}
case 3:
system("cls\n");
int amtDeposit;
printf("Enter amount to deposit:");
scanf("%d", amtDeposit);
balance += amtDeposit;
printf("1- Another Transaction 2- Get Card Back\n");
scanf("%d\n", &choice3);
if(choice3 == 2){
printf("Please take your card.\n");
break;
}
case 4:
system("cls\n");
printf("Your Balance is: $%d\n", balance);
printf("1- Another Transaction 2- Get Card Back\n");
scanf("%d\n", &choice3);
if(choice3 == 2){
printf("Please take your card.\n");
break;
}
case 5:
printf("Please take your card.\n");
break;
}
}
while(choice3 != 2);
return (0);
}