Question about C++ "Menus"

I am looking for a source code containing a menu, I believe a switch case? All I remember is it has:
1
2
3
case 1;
cout << 
break;


Any comments? Oh and I would like for it to have something like default Sorry if that is not much help
I don't think you will get any source code...but you can easily make one yourself after reading: http://www.cplusplus.com/doc/tutorial/control.html#switch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string menuChoices[] = {"Waffles","Pancakes","Eggs & Toast","Cereal"}; //Choices for the menu
  cout<<"What would you like for breakfast?"<<endl;
  for (int i=0;i<4;i++)
  {
    cout<<i+1<<"\t\t"<<menuChoices[i]<<endl; //Prints every choice in the menu like:
    //1		Waffles
    //2		Pancakes
    //etc...
  }

  int myChoice;
  cout<<"(Please enter a number): ";
  cin>>myChoice; //get the choice

  switch (myChoice)
  {
    case 1:
      cout<<"Ahh waffles are our signature dish. They'll be right out."<<endl;
      break;
    case 2:
      cout<<"Oh you'd like Pancakes? Good choice. We are famous for our delicious buttermilk pancakes."<<endl;
      break;
    case 3:
      cout<<"Eggs & Toast? A tad casual but everybody loves a breakfast they could have easily made at home!"<<endl;
      break;
    case 4:
      cout<<"Cereal? Why in the world would you come to a restaurant and have cereal... You're crazy!"<<endl;
      break;
  }

  return 0;
}


So there you go..

Though this is supposed just supposed to be an example of application of the switch statement, not a tutorial. Like firedraco said, you can read that in the tutorial section.

Also, don't often expect source code like this to just kindof appear.. I'm just hungry and haven't reached my programming quota for the day :D
uh I guess Zaita is trying to subtly tell me my source code is poor practice so FINE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <sstream>
//...
int myChoice;
while (1)
{
  for (int i=0;i<4;i++)
    {
      cout<<i+1<<"\t\t"<<menuChoices[i]<<endl; //Prints every choice in the menu like:
      //1		Waffles
      //2		Pancakes
      //etc...
    }
    string input="";
    cout<<"(Please enter a number): ";
    getline(cin,input);
    stringstream ssinput(input);
    if (ssinput >> myChoice)
    {
      if (myChoice<=4 && myChoice>0)
        break;
    }

  cout<<endl;
}

//... 


happy??

Last edited on
Wasn't a hint at you. It was a hint for the OP to do some reading and not ask out-right for people to do their homework/assignment without actually making any effort themselves.
oh.. well that article is kindof irrelevant to the topic's main question..

I mean it doesn't even cover the switch statement... so I was surprised u would link to it in this topic unless u were addressing my poor use of cin>> :P
The switch statement has been explained by yourself. I pre-emptively answered the next question of how to limit input because using >> doesn't work properly blah blah. Usual BS.
Topic archived. No new replies allowed.