Thread: Menu program help

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

    Menu program help

    I am trying to write a menu program that will be broken down into a series of calls to function for each of the menu items. Two of the menu items will be simple programs which I wrote.

    I want two of the functions to run one of the two programs I am trying to include as items in the menu.

    So far I am only familiar with variables, loops, if statements, and I just learned how to write functions.

    The problem I am have is that I don't quite understand how to write a function that will run one of the two programs. Also I am having a hard time writing the program in away that would allow the user to select the menu items.

    Could some please help me figure this out.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int beer_on_the_wall()
    {int i=100;
        while( i <100 && i >=0)
        {
            cout << "Bottles of beer on the wall.";
            i--;
        }
    }
    
    int calculate()
    {
        int arg1;
        int arg2;
    
        cout <<"input argument one";
        cin >> arg1;
        cout <<"input argument two";
        cin >> arg2;
    
        cout << arg1 << "*" << arg2 << "=" << arg1*arg2 << endl;
        cout << arg1 << "+" << arg2 << "=" << arg1+arg2 << endl;
        cout << arg1 << "-" << arg2 << "=" << arg1-arg2 << endl;
    }
    
    void Exit()
    {}
    
    int main ()
    {
        int input;
    
        cout << "1. Play beer\n";
        cout << "2. load calculator\n";
        cout << "3. Exit\n";
        cout << "Selection: ";
        cin >> input;
        switch ( input )
        {
        case 1:            // Note the colon after each case, not a semicolon
      beer_on_the_wall();
      break;
        case 2:
      calculate();
      break;
        case 3:
      Exit();
      cout <<"Good Bye\n";
      break;
    
        default:            // Note the colon for default, not a semicolon
      cout << "Error, bad input, quitting\n";
      break;
        }


    Code:
    
    

  2. #2
    Registered User
    Join Date
    Jun 2013
    Posts
    56
    This while loop will never run.
    Code:
    int beer_on_the_wall()
    {int i=100;
        while( i <100 && i >=0)
        {
            cout << "Bottles of beer on the wall.";
            i--;
        }
    }


    You declare your counter as 100 and ask the while loop to only run if the counter is less than 100.

    Format the code in your main function much better

    If you need to write a function to handle the menu part of it you can move your code in main into a function and then have main call that function.

Popular pages Recent additions subscribe to a feed

Similar Threads

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