Menus in C++

I am trying to add a menu option called "Manager Menu" in the code that I have provided. I have attempted to already, but am stuck on what to do next. I am relatively new with C++ so I'm not sure what I'm doing incorrectly. I need the Manager Menu to have the options for an Inventory Report and a Transaction report. Any help to tell me what I've done wrong?

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//*****************************************************
// Author: D.S. Malik
// 
// This program uses the classes cashRegister and 
// dispenserType to implement a fruit juice machine.
// ****************************************************

#include <iostream>
#include "cashRegister.h"
#include "dispenserType.h"

using namespace std;

void showSelection();
void sellProduct(dispenserType& product, cashRegister& pCounter);

int main()
{
    cashRegister counter;
    dispenserType appleJuice(100, 50); 
    dispenserType orangeJuice(100, 65);
    dispenserType mangoLassi(75, 45);
    dispenserType fruitPunch(100, 85);

    int choice;  //variable to hold the selection

    showSelection();
    cin >> choice;

    while (choice != 9)
    {
        switch (choice)
        {
        case 1: 
            sellProduct(appleJuice, counter);
            break;

        case 2: 
            sellProduct(orangeJuice, counter);
            break;

        case 3: 
            sellProduct(mangoLassi, counter);
            break;

        case 4: 
            sellProduct(fruitPunch, counter);
            break;

		case 5:
			cout << "Manager Menu" << endl;
	    cout << "1 for Inventory Report" << endl;
		cout << "2 for Transaction Report" << endl;

        default: 
            cout << "Invalid selection." << endl;
        }//end switch

        showSelection();
        cin >> choice;
    }//end while

    return 0;
}//end main

void showSelection()
{
    cout << "*** Welcome to Shelly's Fruit Juice Shop ***"
         << endl;
    cout << "To select an item, enter " << endl;
    cout << "1 for apple juice" << endl;
    cout << "2 for orange juice" << endl;
    cout << "3 for mango lassi" << endl;
    cout << "4 for fruit punch" << endl;
	cout << "5 for manager menu" << endl;
    cout << "9 to exit" << endl;
	
	
	     
}//end showSelection

void sellProduct(dispenserType& product, cashRegister& pCounter)
{
    int amount;  //variable to hold the amount entered
    int amount2; //variable to hold the extra amount needed

    if (product.getNoOfItems() > 0) //if the dispenser is not empty
    {
        cout << "Please deposit " << product.getCost()
             << " cents" << endl;
        cin >> amount;

        if (amount < product.getCost())
        {
            cout << "Please deposit another "
                 << product.getCost()- amount << " cents" << endl;
            cin >> amount2;
            amount = amount + amount2;
       }

        if (amount >= product.getCost())
        {
            pCounter.acceptAmount(amount);
            product.makeSale();
            cout << "Collect your item at the bottom and enjoy."
                 << endl;
        }
        else
            cout << "The amount is not enough. " 
                 << "Collect what you deposited." << endl;

        cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
             << endl << endl;
    }
    else
        cout << "Sorry, this item is sold out." << endl;
}//end sellProduct
With the code I have, my options are being shown, but it is also saying "invalid selection" and shows the original menu items as well. I can't figure out how to get rid of invalid selection and make option 5 a valid selection.
you're missing a break in your 'case 5' section, so flow is spilling into the 'default' section.
Thank you...that got rid of the invalid selection message but how do you get rid of the menu items popping up as well? It's displaying the desired output, as well as the original menu selections. I would only like the selections under the "Manager Menu" to be displayed. Not sure how to go about doing that.
Look at your program flow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
        case 5: // <- this case label enters
            cout << "Manager Menu" << endl;   // <- this stuff is printed
            cout << "1 for Inventory Report" << endl;
            cout << "2 for Transaction Report" << endl;
            break;  // <- assuming you add this, this will exit the switch

        default: 
            cout << "Invalid selection." << endl;
        }//end switch
        // <- once switch is exited, the program will continue running from here

        showSelection();  // <- here's where you print the menu again
        cin >> choice;  // <- and get their option for the main menu
    }//end while 


You probably don't want to exit the switch immediately, but rather want to get (and process) user input for 5's submenu.
Topic archived. No new replies allowed.