okay, so i need to make a stimulated ATM in C for my programming class, i've made it, but it doesn't run the whole code properly, it stops at wherever there the 2nd scanf is.
here my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int p(balance){
char option, trans, secop, secopd;
do{
printf("what transaction would you like to do\n");
printf(" W-Withdraw D-Deposit\n");
printf(" C-Check Balance P-Pay bills\n");
printf(" Q-Quit\n\n");
scanf("%c", &option);
if (option=='w'){
printf("what's your withdraw amount?\n");
printf(" A $20.00 D $80.00\n");
printf(" B $40.00 E $100.00\n");
printf(" C $60.00 F Cancel\n");
scanf("%c", &secop);
if(secop=='a'){
printf("$20.00 withdrawn\n");
balance-20;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secop=='b'){
printf("$40.00 withdrawn\n");
balance-40;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secop=='c'){
printf("$60.00 withdrawn\n");
balance-60;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secop=='d'){
printf("$80.00 withdrawn\n");
balance-80;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secop=='e'){
printf("$100.00 withdrawn\n");
balance-100;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secop=='f'){
return balance;
}
}
if (option=='d'){
printf("what's your deposit amount?\n");
printf(" A $20.00 D $80.00\n");
printf(" B $40.00 E $100.00\n");
printf(" C $60.00 F Cancel\n");
scanf("%c", &secopd);
if(secopd=='a'){
printf("$20.00 deposited\n");
balance+20;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secopd=='b'){
printf("$40.00 deposited\n");
balance+40;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secopd=='c'){
printf("$60.00 deposited\n");
balance+60;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(option=='d'){
printf("$80.00 deposited\n");
balance+80;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(secopd=='e'){
printf("$100.00 deposited\n");
balance+100;
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(option=='f'){
return balance;
}
}
if(option=='c'){
printf("%i", balance);
printf("\nwould you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if(option=='p'){
int account, amount;
printf("\nplease enter the account's number that you wish to pay your bills to:\n");
scanf("%i", &account);
printf("how much is your bill?\n");
scanf("%i", &amount);
printf("$%i.00 is paid to %i", amount, account);
printf("would you like to make another transaction?[Y/N]\n");
scanf("%c", &trans);
if(trans=='n'){
return balance;
}
}
if (option=='q'){
return balance;
}
}
while(trans=='y');
return balance;
}
int main(void) {
int balance;
balance = rand() % 500 + 270;
printf(" ++++++++\n");
printf(" +RBNWSS+\n");
printf(" ++++++++\n");
p(balance);
return 0;
}
so what's my error, i've removed a lot of code in order for it to run, for example, it's suppose to ask the user for there pin, and it should only proceed if the pin entered is 1234, but with the pin code in place, if statements seems to loose its function.
help would be greatly appreciated