Thread: Use function prototype and function definition in ATM menu

  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.

    Use function prototype and function definition in ATM menu-atm_menu-png
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you could try and compile it.

    Then remove the Initial Caps From Pretty Much Everything.
    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.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    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.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  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, 01: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, 01:28 PM