Like Tree1Likes
  • 1 Post By Salem

Use function prototype and function definition in ATM menu

This is a discussion on Use function prototype and function definition in ATM menu within the C Programming forums, part of the General Programming Boards category; Dear all, I m a newbie in C. When do the questions in "C Programming for Absolute Beginners" (MICHAEL VINE, ...

  1. #1
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18

    Use function prototype and function definition in ATM menu

    Dear all,

    I m a newbie in C. When do the questions in "C Programming for Absolute Beginners" (MICHAEL VINE, 2008)

    When talked about structure programming, there is a question.

    Write A function that prints an ATM menu—it receives no
    parameters and returns no value.

    Name:  atm_menu-it.png
Views: 1808
Size:  19.0 KB
    Then i write the following:

    Code:
    Void displaymenu()
    /*********************
    Function Prototypes
    *********************/
    Int display_balance();
    Int deposit_funds();
    Int transfer_funds();
    Int withdraw_funds();
    Int get_available_balance();
    Int compare_balance_to_request();
    Int update_account();
    Int disperse_funds();
    Int reject_request();
    Int print_receipt();
    Int verify_ample_funds_exist();
    Int initiate_mechanical_process();
    Int update_bank_records();
    Int atm_lv1() = 0;
    Int atm_lv2() =0;
    Int atm_lv3() =0;
     
    main()
            {
            Do 
                    {
                    System(“Clear”);
                    Printf(“\n\t Welcome to ATM\n\n”);
                    Printf(“1\tDisplay Balance\n”);
                    Printf(“2\tDeposit Funds\n”);
                    Printf(“3\tTransfer Funds\n”);
                    Printf(“4\tWithdraw Funds\n”);
                    Printf(“5\tQuit\n”);
                    Printf(“\n\n Choose number\n”);
                    Scanf(“%d”, &atm_lv1);
                    Switch(atm_lv1) {
                            Case 1:
                            Int display_balance(); // Suppose another function calling for the account?
                            Printf(“Your Balance is”);
                            Break;
                            Case 2:
                            Int Deposit_funds(); //another interface to detect the amount of banknotes?
                            Break;
                            Case 3:
                            Int Transfer_funds(); //Transfer the amount of fund, enter another account
                            Break;
                            Case 4:
                            Int Withdraw_fund();
                            Break;
                            }
                    } while (atm_lv1!=5);
            }// end of ATM level 1
    /***************
    Function Definition
    ****************/
    //display balance
    Int display_balance();
    {
            Printf(“Your account balance is”);
    }
    //disposit fund
    Int Deposit_funds();
    {
            Printf(“You have deposit to your account”);
    }
    //transfer fund
    Int transfer_funds();
    {
            Printf(“You have transferred funds”);
    }
    //withdraw fund
    Int withdraw_funds();
    {
            Do 
            {
            System(“Clear”);
            Printf(“\n\t Withdraw funds options \n\n”);
            Printf(“1\tGet Available Balance\n”);
            Printf(“2\tCompare Balance to Request\n”);
            Printf(“3\tUpdate Account\n”);
            Printf(“4\tDisperse Funds\n”);
            Printf(“5\tReject Request\n”);
            Printf(“6\tPrint Receipt\n”);
            Printf(“7\tReturn\n”);
            Printf(“\n\n Choose number\n”);
            Scanf(“%d”, &atm_lv2);
            Switch(atm_lv2) {
                    Case 1:
                    Int get_available_balance(); 
                    Break;
                    Case 2:
                    Int compare_balance_to_request(); 
                    Break;
                    Case 3:
                    Int update_account (); 
                    Break;
                    Case 4:
                    Int disperse_fund();
                    Break;
                    Case 5:
                    Int reject_request();
                    Break;
                    Case 6:
                    Int print_receipt();
                    Break;
                    Case 7:
                    Int main();
                    Break;
                    }
            } while (atm_lv2!=8);
    }// end of ATM level 2
     
    /***************
    Function Definition
    ****************/
    //Get available balance
    Int get_available_balance();
    {
            Printf(“Your available balance is”);
    }
    //Compare balance to request
    Int compare_balance_to_request();
    {
            Printf(“Your balance is compared”);
    }
    //update account
    Int update_account();
    {
            Printf(“Your account is updated”);
    }
    //disperse funds
    Int disperse_fund(int);
    {
    Do 
            {
            System(“Clear”);
            Printf(“\n\t Select the Disperse Funds Action”);
            Printf(“1\tVerify Ample Fund\n”);
            Printf(“2\tInitiate Mechanical Process\n”);
            Printf(“3\tUpdate Bank Record\n”);
            Scanf(“%d”,&atm_lv3);
            Switch(atm_lv3){
                    Case 1:
                    Int verify_ample_funds_exist();
                    Case 2:
                    Int initiate_mechanical_process();
                    Case 3:
                    Int update_bank_records();
            } while(atm_lv3!=4);
    } //end of atm lv3
    //reject request
    Int reject_request(int);
    {
            Printf(“Your request is rejected”);
    }
    //print receipt
    Int print_receipt();
    {
            Printf(“Your receipt is being printed”);
    }
    //Verify amply funds
    Int verify_ample_funds_exist();
    {
            Printf(“Your fund is verified”);
    }
    //initiate mechanical process
    Int initiate_mechanical_process();
    {
            Printf(“Mechanical process initiated”);
    }
    //update bank record
    Int update_bank_records();
    {
            Printf(“Bank records updated”);
    }

  2. #2
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Any incorrect or improvement needed?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    Well you could try and compile it.

    Then remove the Initial Caps From Pretty Much Everything.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,614
    I suggest never using a word processor to write code!

    Smart quotes are very hard for newbies to figure the error messages caused by them.

    Your code with smart quotes
    Code:
    Scanf(“%d”,&atm_lv3);

    Your code with the correct double quotes and lower case "scanf"
    Code:
    scanf("%d",&atm_lv3);
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Thanks all,
    I will try to compile the file tonight.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function prototype
    By Lina_inverse in forum C Programming
    Replies: 6
    Last Post: 10-07-2012, 08:59 PM
  2. Function Prototype
    By popnfresh12321 in forum C Programming
    Replies: 1
    Last Post: 05-06-2012, 09:36 PM
  3. Why put the prototype inside the function definition?
    By Overworked_PhD in forum C Programming
    Replies: 14
    Last Post: 01-11-2010, 12:48 PM
  4. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  5. Function Prototype and Definition
    By XDarklytez in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2005, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21