Thread: ATM Menu Program

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    33

    ATM Menu Program

    Hey all,

    I have a couple of compiler errors that I'm running into that I can't figure out how to correct them. The assignment calls for a program that simulates an ATM menu, using classes and objects. I keep getting the following compiler errors:

    1>------ Build started: Project: Lab06, Configuration: Debug Win32 ------
    1> MenuBuilderClass.cpp
    1>c:\users\user\documents\visual studio 2012\projects\lab06\lab06\menubuilderclass.cpp(97) : warning C4715: 'processAnswer' : not all control paths return a value
    1>TestMenu.obj : error LNK2019: unresolved external symbol "public: int __thiscall MenuBuilder::buildMenu(void)" (?buildMenu@MenuBuilder@@QAEHXZ) referenced in function _main
    1>TestMenu.obj : error LNK2019: unresolved external symbol "public: int __thiscall MenuBuilder:rocessAnswer(int)" (?processAnswer@MenuBuilder@@QAEHH@Z) referenced in function _main
    1>C:\Users\User\Documents\Visual Studio 2012\Projects\Lab06\Debug\Lab06.exe : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    The code I have is below:

    Menubuilder.h

    Code:
    #ifndef MENU_BUILDER_H
    #define MENU_BUILDER_H
    
    using namespace std;
    
    class MenuBuilder
    {
    public:
        MenuBuilder();
        int buildMenu();
        int processAnswer(int);
    
    private:
        double CurrBal;
    };
    
    #endif
    MenuBuilderClass.cpp

    Code:
    #include <iostream>
    #include "MenuBuilder.h"
    using namespace std;
    
    MenuBuilder::MenuBuilder()
    {
        double CurrBal = 2439.95;
    }
    
    int buildMenu()
    {
        cout << "Welcome to the Devry Automated Teller Machine." << endl;
        cout << "----------------------------------------------" << endl;
        cout << endl;
        cout << "1. Check balance." << endl;
        cout << "2. Make withdrawal." << endl;
        cout << "3. Make deposit." << endl;
        cout << "4. View account information." << endl;
        cout << "5. View statement." << endl;
        cout << "6. View bank information." << endl;
        cout << "7. Exit." << endl;
        cout << endl;
        cout << "Please make a selection from the above menu." << endl;
        return 0;
    }
    
    int processAnswer(int answer)
    {
        double CurrBal = 2439.95;
        double NewBal = 0.00;
    
        switch (answer)
        {
            case '1':
                cout << "Your account balance is " << CurrBal << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
        
            case '2':
                cout << "How much would you like to withdraw from your account?" << endl;
                double withdraw;
                cin >> withdraw;
                NewBal = CurrBal - withdraw;
                cout << "You withdrew $ " << withdraw << endl;
                cout << "Your new account balance is $ " << NewBal << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
    
            case '3':
                cout << "How much would you like to deposit to your account?" << endl;
                double deposit;
                cin >> deposit;
                NewBal = CurrBal + deposit;
                cout << "You deposited $ " << deposit << endl;
                cout << "Your new account balance is $ " << NewBal << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
    
            case '4':
                cout << "Name: John Worley" << endl;
                cout << "Account Number: 1234554321" << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
    
            case '5':
                cout << "1/11/11 - McDonald's - $6.27" << endl;
                cout << "1/15/11 - Kwik Trip - $34.93" << endl;
                cout << "2/28/11 - Target - $124.21" << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
    
            case '6':
                cout << "Devry Bank, established 2011" << endl;
                cout << "(123) 456-7890" << endl;
                cout << "12345 1st. St." << endl;
                cout << "Someplace, NJ. 12345" << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
    
            case '7':
                cout << "Thank you for using Devry Bank's Automated Teller Machine." << endl;
                cout << "Good-bye" << endl;
                break;
            default:
                cout << "Invalid selection." << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
            return answer;
        }
    }
    TestMenu.cpp

    Code:
    #include <iostream>
    #include <iomanip>
    #include "MenuBuilder.h"
    using namespace std;
    
    int main()
    {
        MenuBuilder transaction;
        int answer = 0;
    
        while (answer != 7)
        {
            transaction.buildMenu();
            cin >> answer;
            transaction.processAnswer(answer);
        }
        system("pause");
        return 0;
    }
    I feel like I'm overlooking something simple, but I just don't see it.
    Anyone have any thoughts??

    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > MenuBuilder::MenuBuilder()
    Why do you think this symbol works

    > int buildMenu()
    And this one doesn't.
    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.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    If we look inside the switch case statement in ProcessAnswer():
    Code:
            default:
                cout << "Invalid selection." << endl;
                cout << endl;
                cout << "Please make a selection from the above menu." << endl;
                break;
            return answer;
        }
    The return statement is in the case statement. Normally this is fine, but there are two problems: one, the return statement does not apply in all cases, and two, even in the default case, the return statement appears after the break. I don't think that the return statement is ever going to be reached. Consider that control of the program leaves the switch case at the break, so execution would continue after the closing brace. Move the return statement.

    The linker errors are related to how you declared class member functions, but actually defined global free functions instead. Make sure that your member functions are actually part of the class when you define them, i.e.

    Code:
    int MenuBuilder::buildMenu()
    {
      // ...
    }
    
    int MenuBuilder::processAnswer(int answer)
    {
      // ...
    }

  4. #4
    Registered User
    Join Date
    Aug 2013
    Posts
    33
    See....I knew it was something simple. The program compiles and runs as expected now. Thanks for the help...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with menu program
    By leroyjenkens in forum C Programming
    Replies: 1
    Last Post: 06-15-2012, 03:21 PM
  2. Need big help with a menu program
    By angelofmyst in forum C Programming
    Replies: 7
    Last Post: 12-18-2010, 07:34 PM
  3. Menu program
    By DerrickakaDRoC in forum C Programming
    Replies: 7
    Last Post: 12-12-2010, 05:09 PM
  4. Menu-Driven Program Help...
    By eun-jin in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2006, 02:58 PM
  5. A Menu Program
    By Aidanjames86 in forum C++ Programming
    Replies: 6
    Last Post: 03-27-2006, 06:44 AM