Thread: bank menu (algorithm with repetitions)

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    1

    Question bank menu (algorithm with repetitions)

    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?

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    You need to learn about loops.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check repetitions
    By Daniel Santos in forum C Programming
    Replies: 5
    Last Post: 01-19-2012, 01:22 PM
  2. Bank Loans
    By terrydc50 in forum C++ Programming
    Replies: 2
    Last Post: 03-09-2009, 06:59 AM
  3. Bank like system
    By Signpost in forum C Programming
    Replies: 20
    Last Post: 03-30-2008, 12:52 PM
  4. bank of oscillators
    By reakinator in forum C Programming
    Replies: 3
    Last Post: 04-17-2006, 06:23 AM
  5. Bank Account
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 09-14-2003, 02:27 AM

Tags for this Thread