I know everything that i want to do but i never did a menu before so i dont know how to go about doing so if at all possible can someone post a sample program that uses a menu-selection with subprograms for each. This here is something like what i want my program to do


I have a soft drink distrubutorship company that sells coca-cola(id number 1), pepsi(id number 2), sprite(id number 3), and root-beer(id number 4) by the case.

The menu will do the following:

(e) enter invetory
(p) purchase sode
(s) sold soda
(d) display inventory
(q) quit

I will promt the user to enter the inventory for each brand at the start of the week and then process all weekly sales and purchase records for each brand.

Each transaction will consist of 2 data items which are 1) brand identification number and 2) the amount purchased (a positive interger) or the amount sold (a negative integer). It is already assumed that i have sufficient foresight to prevent depletion of my inventory for all the brands. Also the the display of my weekly inventory will contain the brand's name.

everything is inputted from the keyboard.

#include <iostream>

using namespace std;

char menu()
{
  const char *options[] = {
    "(e) enter invetory",
    "(p) purchase sode",
    "(s) sold soda",
    "(d) display inventory",
    "(q) quit",
    0
  };
  char ret;

  for (const char **p = options; *p != 0; p++)
    cout<< *p <<'\n';
  cout<<"Selection: ";
  ret = cin.get();
  cin.ignore(cin.rdbuf()->in_avail());

  return ret;
}

int main()
{
  char opt;

  while ((opt = menu()) != 'q') {
    switch (opt) {
      case 'e': cout<<"You chose e"<<endl; break;
      case 'p': cout<<"You chose p"<<endl; break;
      case 's': cout<<"You chose s"<<endl; break;
      case 'd': cout<<"You chose d"<<endl; break;
      default: cout<<"Invalid option"<<endl; break;
    }
  }

  cin.get();
}

If you need me to explain any of that, feel free to ask. It's not quite as simple as the typical "print/switch" menu, but it's very close.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.