Restaurant Management

I am trying to get the user to order an item from the menu after they have input all the data (eg. # of tables, # of items, item names and item ID...). After the user enters what item they with to order from what table, I try to check if what they enter is a valid order, then nothing happens...

If I need to post more of the code I have, please let me know.
Thank you.

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
85
86
87
88
89
90
91
92
93
94
//==============Before main routine===================

struct Item {
    string ItemID; //the menu item ID
    string Name; //the menu item name
    int Max; //the maximum number of orders available for item
    float Price; //the menu item price
    int Available;
};

struct Table {
    int tablenum;
    int Bill;
    int orders;
    string Orders[];
};
  
struct OrderList {
    int FromTable;
    string IDOrdered;
    OrderList *next;
};

//=================inside main routine=====================
...
//array of structs with menu item info...
Item *ItemNumber = new Item[n] //user has entered number 'n'
                              // representing how many items there are to order
case Order:
    int t;//table number
    int i;//item nuumber
    //what table is ordering...
    
    bool valid;
    bool check;
    do{
        valid=false;
        cout << endl;
        cout<< "what table number is placing an order?" << endl;
        cin >> t;
        
        // then check if table number is valid...
        if ((t<=T) && (t>0)){
            valid=true;
        }else{
            cout<<"***table "<<t<<", is not recognized***";
            cout<<endl;
        }
    }while(valid==false);
    
    //what item is being ordered...
    valid = false;
    do{
        cout << endl;
        cout << "what is the item's ID that table " << t;
        cout << " wishes to order?" << endl;
        cin >> ID;
        // then check if item ID is valid...
        check = false;
        do{
             
            i = 0;
            if(ID == ItemNumber[i].ItemID){
                if(ItemNumber[i].Available>0){
                    cout<<endl<<endl;
                    cout<<ItemNumber[i].Name;
                    cout<<", is available for order!"<<endl;
                    cout<<endl;
                    valid=true;
                    check=true;
                    ItemNumber[i].Available=ItemNumber[i].Available-1;
                }else{
                    cout<<"*** There are no more orders available for ";
                    cout<<ItemNumber[i].Name<<" ***";
                    break;
                }
            
            }else{
                i++;
            }
        }while((check==false)||(i<n));
        if(valid == false){
            cout<<"***item ID "<<ID<<", is either not recognized";
            cout<<" or out of order***";
            cout<<endl;
        }
    }while(valid == false);
    //add data to table struct.
    TableNumber[t].tablenum = t;
    TableNumber[t].orders ++;
    TableNumber[t].Bill=TableNumber[t].Bill+ItemNumber[i].Price;
    TableNumber[t].Orders[TableNumber[t].orders]=ItemNumber[i].Name;
    break;
...


Please show us the output that you are getting as well as the output you expect.

Also, this appears to be a fairly general C++ question rather than one that's Unix-specific. In the future, you will probably get a better response in either the Beginner forum or the General forum.

I think your while condition on line #81 is always true.

First, just add line #63 below to understand whats happening.

The check var is not really needed - lines #59 and #70 can be removed
Move the break in line #75 to run after the availability check - to line #77
Remove the check==false from the while condition on line #81
If an item doesn't exist, the loop will never exit even when i is greater than n
and endless loop condition
Changing condition to i < n while guarantee the loop will exit at some point

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
85
86
87
        // then check if item ID is valid...
        check = false;
        do{
             
            i = 0;
            cout << "Checking item " << i << endl;  // see if we ever leave the loop
            if(ID == ItemNumber[i].ItemID){
                if(ItemNumber[i].Available>0){
                    cout<<endl<<endl;
                    cout<<ItemNumber[i].Name;
                    cout<<", is available for order!"<<endl;
                    cout<<endl;
                    valid=true;
                    ItemNumber[i].Available=ItemNumber[i].Available-1;
                }else{
                    cout<<"*** There are no more orders available for ";
                    cout<<ItemNumber[i].Name<<" ***";
                }
                break; // stop searching
         
            }else{
                i++;
            }
        }while( i < n );  
        if(valid == false){
            cout<<"***item ID "<<ID<<", is either not recognized";
            cout<<" or out of order***";
            cout<<endl;
        }

Last edited on
Topic archived. No new replies allowed.