Heyguys,
I’m trying to write the code of a bank menu. The part i’ve already done is:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
char account, operation;
float account1, account2, account3, value;
printf("***********************************\n");
printf("PORTAL OF XBANK\n");
printf("***********************************\n");
printf("Tap your account number or 0 to close:\n");
account = getchar();
while(account != '0' && account != '1' && account!= '2' && account != '3') {
printf("Unnexisting account! Try again!\n");
printf("Tap your acount:\n");
account = getchar();
}
if(account == '1') {
printf("***********************************\n");
printf("OPERATIONS\n");
printf("***********************************\n");
printf("(1)Deposit\n");
printf("(0)Return\n");
printf("***********************************\n");
printf("Choose an option:\n");
scanf("%c", &operation);
while(operation == '0'){
printf("***********************************\n");
printf("PORTAL OF XBANK\n");
printf("***********************************\n");
printf("Tap your acount or 0 to close:\n");
account = getchar();
}
if(operation == '1') {
printf("Deposited value (US$):\n");
scanf("%f", &value);
account1 += value;
printf("Deposit succesfully made!");
}
} else if(account == '2') {
printf("***********************************\n");
printf("OPERATIONS\n");
printf("***********************************\n");
printf("(1)Deposit\n");
printf("(0)Return\n");
printf("***********************************\n");
printf("Choose an option:\n");
operation = getchar();
while(operation == '0'){
printf("***********************************\n");
printf("PORTAL OF XBANK\n");
printf("***********************************\n");
printf("Tap your account or 0 to close:\n");
account = getchar();
}
if(operation == '1') {
printf("Deposited value (US$):\n");
scanf("%f", &value);
account2 += value;
printf("Deposit succesfully made!");
}
} else if(account == '3') {
printf("***********************************\n");
printf("OPERATIONS\n");
printf("***********************************\n");
printf("(1)Deposit\n");
printf("(0)Return\n");
printf("***********************************\n");
printf("Choose an option:\n");
operation = getchar();
while(operation == '0'){
printf("***********************************\n");
printf("PORTAL OF XBANK\n");
printf("***********************************\n");
printf("Tap your account or 0 to close:\n");
account = getchar();
}
if(operation == '1') {
printf("Deposited value (US$):\n");
scanf("%f", &value);
account3 += value;
printf("Deposit succesfully made!");
}
while(operation != '1' && operation != '0'){
printf("Unvalid operation! Try again!\n");
printf("Choose an option:");}
}
return 0;
}
As you can see, it still only has the operation of deposit. There are 3 accounts in that bank, the first one is accessed through the number 1, the second one through the number 2, and the third one through the number 3. However, when I made the test, I got 2 problems:
1 - Everytime I tap an unnexisting account number, the program must show a message asking for it again. That message appears twice, and I just don't know why! When I use if instead of while, it only appears once, but I need to use while because the message must appeare however many times I tap an unvalid account number.
2 - When I tap an existing account number, the program must show another menu with the options of deposit and return, and that reads the option that I tap. That menu appears, but it just doesn't read what I tap. The program finishes there and I also don't know the reason for that
What are my mistakes?