menu(loop)problem from jumping into C++

HI everyone! started c++ programming 2 days ago. I am using jumping into C++.couldn't get my head around a practice problem from there. Problem is:

write a menu program that lets user select from a list of options and if input is not one of the option, reprint the list.

problem is if there are 'n' dishes, how to accept less than 'n' input. could anyone please the code for it?

> could anyone please the code for it?

no you dont learn that way

where did n dishes/n input come in? if you could post the problem on here we could certianly walk you through it
the problem, (as it is) is:


"write a menu program that lets user select from a list of options and if input is not one of the option, reprint the list."

remember right now i only know the concept of if statements and loop(only 2 days into c++)

1. now if i provide option of 4 dishes(using cout) for which I declare 4 variables, how could I accept input from user if he only wants to order, say, 2 or 3 dishes. how would he skip the option for choosing no more dishes that he doesn't want?

2. also how to check if he didn't choose an option from the menu(entered sth else unavailable in the menu). i mean i could provide option of 1. chicken(variable a) 2. milk(variable b). but what if he doesn't necessarily choose in that order. eg: he first orders milk and then chicken. so would I have to write the lengthy code: that is :

if(a!=chicken || a!=milk || b!=chicken || b!=milk), then loop.


these two concepts is troubling me in this problem. also this is my first time in forum ever. so plz play nice. and for the
>could anyone please the code for it?
just could find answer. so asking the code in these concepts. waiting for answer.
I came up with an answer(after a lot and lot and lot of thought).so just posting the answer of my code (may be others in the future bugged by the same problem.)
also any sort of constructive criticism or other suggestion to make the code better is highly weclomed.


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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string dish1;
    string dish2;
    string dish3;
    string dish4;

        do
        {
            cout << "we serve momo, chicken, burger and fries. if don't want to order more, type 'N'. enter your order\n";
            cout<<"1. ";
            cin >> dish1;
            if (dish1=="N")
            {
                break;
            }
            cout<<"2. ";
            cin >> dish2;
            if (dish1=="momo"||dish1=="chicken"||dish1=="burger"||dish1=="fries")
            {
                if(dish2=="N")//nested if statement so that only consumer gave a valid order, then he can type "N" and quit his order. Not doing so created a bug that allowed user to type anything in the first order and typing "N" allowed hime to exit.
            {
                break;
            }
            }
            cout<< "3. ";
            cin >> dish3;
            if ((dish1=="momo"||dish1=="chicken"||dish1=="burger"||dish1=="fries")&&(dish2=="momo"||dish2=="chicken"||dish2=="burger"||dish2=="fries"))
            {
                if(dish3=="N")
                {
                    break;
                }
            }
            cout << "4. ";
            cin >> dish4;
            if ((dish1=="momo"||dish1=="chicken"||dish1=="burger"||dish1=="fries")&&(dish2=="momo"||dish2=="chicken"||dish2=="burger"||dish2=="fries")&&(dish3=="momo"||dish3=="chicken"||dish3=="burger"||dish3=="fries"))
            {
                if (dish4=="N")
                {
                    break;
                }
            }





            if(dish1!="momo"&&dish1!="chicken"&&dish1!="burger"&&dish1!="fries"||dish2!="momo"&&dish2!="chicken"&&dish2!="burger"&&dish2!="fries"||dish3!="momo"&&dish3!="chicken"&&dish3!="burger"&&dish3!="fries"||dish4!="momo"&&dish4!="chicken"&&dish4!="burger"&&dish4!="fries")

            {
                cout<<"Invalid input. Please order again!\n";
            }
        }while (dish1!="momo"&&dish1!="chicken"&&dish1!="burger"&&dish1!="fries"||dish2!="momo"&&dish2!="chicken"&&dish2!="burger"&&dish2!="fries"||dish3!="momo"&&dish3!="chicken"&&dish3!="burger"&&dish3!="fries"||dish4!="momo"&&dish4!="chicken"&&dish4!="burger"&&dish4!="fries");
        if (dish1=="N")
        {
            cout<< "You ordered Nothing!\n";
        }
        if (dish2=="N")
        {
            cout<< "You ordered "<<dish1<<endl;
        }
        if (dish3=="N")
        {
            cout << "You order "<<dish1<<" and "<<dish2<<endl;
        }
        if (dish4=="N")
        {
            cout << "You ordered "<<dish1<<", "<<dish2<<", "<<"and "<<dish3;

        }
        else
        {
            cout<< "You ordered "<<dish1<<", "<<dish2<<", "<<dish3<<" and "<<dish4;
        }

    }



Topic archived. No new replies allowed.