Menu Program Help

Hi guys! Ive been looking around the site for sometime while working on my programming assignments for class, and have finally run into an issue where I need some guidance. The chapter we are working on is all about functions.. and that is where my problems began. The Current issue I have is how do I make all of these functions in my program continuously update the 'total cups' and 'total cash'? below is what I currently have. I know there is something wrong with the functions and how I have them, but after working on this for 2 weeks, I just cannot wrap my mind around this by myself.

**Please note: I am not looking for someone to do this problem for me, I just need tips and guidance and yes I have looked at examples of this problem on here, but I am still lost.**

Here is the assignment:

Jason opened a coffee shop at the beach and sells coffee in three sizes: small (9oz), medium (12oz), and large (15oz). The cost of one small cup is $1.75, one medium cup is $1.90, and one large cup is $2.00. Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following:

Buy coffee in any size and in any number of cups.
At any time show the total number of cups of each size sold.
At any time show the total amount of coffee sold.
At any time show the total money made.
The buy coffee option allows the customer to select the number of cups in each of the sizes they want to order and display a receipt for that order. The other three options would be used by the owner to check on the status of the shop during the day. Pay attention to the user interface. Try to minimize the number of mouse clicks and display output neatly.




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
#include <iostream>
#include <iomanip>

using namespace std;

const double SMALL_CUP_COST = 1.75;
const double MEDIUM_CUP_COST = 1.90;
const double LARGE_CUP_COST = 2.00;


// function prototypes
void POS(int & small, int & medium, int & large);
// processes the transaction of a single customer
// program input- Number of large, medium, and small cups the cutomer wants to buy
// program output- Displays the reciept for the customer after the transaction is complete
// preconditions- the numbers of lare, medium, and small cups are intialized at 0 before the transaction begins
// postconditions- the number of large, medium, and small cups sold for this transaction are updated
void sizesSold(int & small, int & medium,int & large);
// outputs the total number of each size sold
void totalCupsSold(int & small, int & medium, int & large);
void totalSales(int & small, int & medium, int & large);
int mainMenu();
// Displays the main menu and gets the user's selection
// Program Inputs - User's selection
// Program Outputs - main menu display
// Postcondition: function returns the user's choice


//*****************************
//      Main Start
//*****************************
int main()
{
    int small=0;// keeps track of total sold by reference in function
    int medium=0;// keeps track of total sold by reference in function
    int large=0; // keeps track of total sold by reference in function
   
    int totalCups=0; // is updated after each transaction
    int choice;//local int variable to receive the user's choice
    choice=mainMenu();// initialize users choice
    
    switch (choice)
    {
        case '1':
            POS(small, medium, large);
            break;
        case '2':
            sizesSold(small,medium,large);
            break;
        case '3':
            totalCupsSold(small, medium, large);
            break;
        case '4':
            totalSales(small, medium, large);
            break;
        default:
            cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
    }
    return 0;
}
//********************************
//      END OF MAIN
//********************************

int  mainMenu()
{
    
    cout << "Please select which option you would like." << endl;
    cout << "1. Buy Coffee" << endl;
    cout << "2. Display the cups of coffee of each size sold" << endl;
    cout << "3. Display the total cups of coffee sold" << endl;
    cout << "4. Display the total amount of money earned" << endl;
    return 0;
}
void POS (int& small, int&  medium, int& large)
{
    
    double transaction;
    
    cout << "Please read the menu, and select the number " << endl;
    cout << "of each size of coffee that you would like to " << endl;
    cout << "purchase." << endl;
    
    cout << "Small Cup........................ $" << showpoint << setprecision(3) << SMALL_CUP_COST << endl;
    cout << "Medium Cup....................... $" << showpoint << setprecision(3) << MEDIUM_CUP_COST << endl;
    cout << "Large Cup........................ $" << showpoint << setprecision(3) << LARGE_CUP_COST << endl;
    cout << "Please enter the number of small cups you would like to purchase: ";
    cin >> small;
    cout << endl;
    cout << "Please enter the number of medium cups you would like to purchase: ";
    cin >> medium;
    cout << endl;
    cout << "Please enter the number of large cups you would like to purchase: ";
    cin >> large;
    cout << endl;
    transaction=(small*SMALL_CUP_COST)+(medium*MEDIUM_CUP_COST)+(large*LARGE_CUP_COST);
    cout<<"Your transction equals $" <<transaction<<endl;
    
}

void totalSales(int small, int& medium, int large, double& totalCash)
{
    totalCash = (SMALL_CUP_COST * small) + (MEDIUM_CUP_COST * medium) + (LARGE_CUP_COST * large);
    cin>>totalCash;
    cout << "Total Sales are: " << showpoint << totalCash << endl;
    
}
Last edited on
closed account (D80DSL3A)
You're doing fine with the coding. I see a couple of function defs missing for sizesSold and totalCupsSold, but those are simple.
One problem I see. You want the values for small, medium and large to be incremented in POS().
I think this is the problem you described as well.
Use a set of local variables for the current order quantities then add these to the totals small, medium and large. eg.
1
2
3
4
5
6
7
cout << "Please enter the number of small cups you would like to purchase: ";
int thisOrderSmall=0;
cin >> thisOrderSmall;
small += thisOrderSmall;// increment global total

// later
transaction=(thisOrderSmall*SMALL_CUP_COST)+...
Last edited on
Ah! incrementing the cups like that makes sense. Thank you!

This is what I have now based on your suggestion. My only problem now is the switch statement always goes to default no matter which option ( 1-4) I pick. Would the switch need to be set up differently? Or would making an if/else loop make more sense?
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <iomanip>

using namespace std;

const double SMALL_CUP_COST = 1.75;
const double MEDIUM_CUP_COST = 1.90;
const double LARGE_CUP_COST = 2.00;


// function prototypes
void POS(int & small, int & medium, int & large);
// processes the transaction of a single customer
// program input- Number of large, medium, and small cups the cutomer wants to buy
// program output- Displays the reciept for the customer after the transaction is complete
// preconditions- the numbers of lare, medium, and small cups are intialized at 0 before the transaction begins
// postconditions- the number of large, medium, and small cups sold for this transaction are updated

void sizesSold(int small, int  medium,int large);
// outputs the total number of each size sold
void totalCupsSold(int small, int  medium, int large);
void totalSales(int small, int medium, int large);
int mainMenu();
// Displays the main menu and gets the user's selection
// Program Inputs - User's selection
// Program Outputs - main menu display
// Postcondition: function returns the user's choice


//*****************************
//      Main Start
//*****************************
int main()
{
    int small=0;  // keeps track of total sold by reference in function
    int medium=0; // keeps track of total sold by reference in function
    int large=0;  // keeps track of total sold by reference in function
    

    int  choice;      //local int variable to receive the user's choice
    choice=mainMenu();// initialize users choice
    
    switch (choice)
    {
        case '1':
            POS(small, medium, large);
            break;
        case '2':
            sizesSold(small,medium,large);
            break;
        case '3':
            totalCupsSold(small, medium, large);
            break;
        case '4':
            totalSales (small,medium,large);
            break;
        default:
            cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
    }

}
//********************************
//      END OF MAIN
//********************************

int   mainMenu()
{
    int choice;
    cout << "Please select which option you would like." << endl;
    cout << "1. Buy Coffee" << endl;
    cout << "2. Display the cups of coffee of each size sold" << endl;
    cout << "3. Display the total cups of coffee sold" << endl;
    cout << "4. Display the total amount of money earned" << endl;
    cin>>choice;
    return 0;
}
void POS (int& small, int&  medium, int& large)
{
    
    double transaction;
    int thisOrderSmall=0;
    int thisOrderMedium=0;
    int thisOrderLarge=0;
    
    cout << "Please read the menu, and select the number " << endl;
    cout << "of each size of coffee that you would like to " << endl;
    cout << "purchase." << endl;
    
    cout << "Small Cup........................ $" << showpoint << setprecision(3) << SMALL_CUP_COST << endl;
    cout << "Medium Cup....................... $" << showpoint << setprecision(3) << MEDIUM_CUP_COST << endl;
    cout << "Large Cup........................ $" << showpoint << setprecision(3) << LARGE_CUP_COST << endl;
    cout << "Please enter the number of small cups you would like to purchase: ";
    cin >> thisOrderSmall;
    small += thisOrderSmall; // increment global total

    cout << endl;
    cout << "Please enter the number of medium cups you would like to purchase: ";
    cin >> thisOrderMedium;
    medium += thisOrderMedium;
    
    cout << endl;
    cout << "Please enter the number of large cups you would like to purchase: ";
    cin >> thisOrderLarge;
    large += thisOrderLarge;
    
    transaction=(thisOrderSmall*SMALL_CUP_COST)+(thisOrderMedium*MEDIUM_CUP_COST)+(thisOrderLarge*LARGE_CUP_COST);
    cout<<"Your transction equals $" <<transaction<<endl;
    
}

void totalSales(int small, int medium, int large)
{
    double totalCash;
    totalCash = (SMALL_CUP_COST * small) + (MEDIUM_CUP_COST * medium) + (LARGE_CUP_COST * large);
    cin>>totalCash;
    cout << "Total Sales are: " << showpoint << totalCash << endl;

}

void totalCupsSold(int small, int medium, int large)

{
    double totalCups;
    totalCups = small + medium + large;
    cout << "The total number of coffee cups sold is: " << totalCups << endl;

}

void sizesSold(int small, int  medium,int  large)
{
 
    cout << "Number of small cups of coffee sold: " << small << endl;
    cout << "Number of medium cups of coffee sold: " << medium << endl;
    cout << "Number of large cups of coffee sold: " << large << endl;
   
   
}
closed account (D80DSL3A)
The return value at the end of mainMenu() doesn't look right.
Just saw that. I'm assuming it should return choice, but even when I change that my switch always goes to default.
closed account (D80DSL3A)
choice is an int. What are those case values? case '1': That's a char value.
Try case 1:, etc.
oh.. I didn't know that's what it meant. Now I have it running and am trying to put a do loop in the main menu to make it keep it going until the user wants to end the program, but I'm just messing the code up overtime i try to put a do look in there. Is there a different way to approach this?
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <iomanip>

using namespace std;


const double small_Ouces=9;
const double medium_Ounces=12;
const double large_Ounces=15;
const double SMALL_CUP_COST = 1.75;
const double MEDIUM_CUP_COST = 1.90;
const double LARGE_CUP_COST = 2.00;


// function prototypes
void POS(int & small, int & medium, int & large);
// processes the transaction of a single customer
// program input- Number of large, medium, and small cups the cutomer wants to buy
// program output- Displays the reciept for the customer after the transaction is complete
// preconditions- the numbers of lare, medium, and small cups are intialized at 0 before the transaction begins
// postconditions- the number of large, medium, and small cups sold for this transaction are updated

void sizesSold(int small, int  medium,int large);
// outputs the total number of each size sold
void totalCupsSold(int small, int  medium, int large);
void totalSales(int small, int medium, int large);
int mainMenu();
// Displays the main menu and gets the user's selection
// Program Inputs - User's selection
// Program Outputs - main menu display
// Postcondition: function returns the user's choice


//*****************************
//      Main Start
//*****************************
int main()
{
    int small=0;  // keeps track of total sold by reference in function
    int medium=0; // keeps track of total sold by reference in function
    int large=0;  // keeps track of total sold by reference in function
    

    int  choice;      //local int variable to receive the user's choice
    choice=mainMenu();// initialize users choice
    
    
    switch (choice) //make sure case same datatype as argument
    {
    case 1:
        POS(small,medium,large);
        break;
    case 2:
        sizesSold(small,medium,large);
        break;
    case 3:
        totalCupsSold(small,medium,large);
        break;
    case 4:
        totalSales(small,medium,large);
        break;
    case 5:
        cout << "Goodbye.\n";
        break;
    default:
        cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
        
    }
    
}


//********************************
//      END OF MAIN
//********************************

int   mainMenu()
{
    int choice;
    cout << "Please select which option you would like." << endl;
    cout << "1. Buy Coffee" << endl;
    cout << "2. Display the cups of coffee of each size sold" << endl;
    cout << "3. Display the total cups of coffee sold" << endl;
    cout << "4. Display the total amount of money earned" << endl;
    cout<< "5. Exit"<<endl;
    cin>>choice; // save choice
    return choice; // return choice to main and into switch
    
}
void POS (int& small, int&  medium, int& large)
{
    
    double transaction;
    int thisOrderSmall=0;
    int thisOrderMedium=0;
    int thisOrderLarge=0;
    
    cout << "Please read the menu, and select the number " << endl;
    cout << "of each size of coffee that you would like to " << endl;
    cout << "purchase." << endl;
    
    cout << "Small Cup........................ $" << showpoint << setprecision(3) << SMALL_CUP_COST << endl;
    cout << "Medium Cup....................... $" << showpoint << setprecision(3) << MEDIUM_CUP_COST << endl;
    cout << "Large Cup........................ $" << showpoint << setprecision(3) << LARGE_CUP_COST << endl;
    cout << "Please enter the number of small cups you would like to purchase: ";
    cin >> thisOrderSmall;
    small += thisOrderSmall; // increment global total

    cout << endl;
    cout << "Please enter the number of medium cups you would like to purchase: ";
    cin >> thisOrderMedium;
    medium += thisOrderMedium;
    
    cout << endl;
    cout << "Please enter the number of large cups you would like to purchase: ";
    cin >> thisOrderLarge;
    large += thisOrderLarge;
    
    transaction=(thisOrderSmall*SMALL_CUP_COST)+(thisOrderMedium*MEDIUM_CUP_COST)+(thisOrderLarge*LARGE_CUP_COST);
    cout<<"Your transction equals $" <<transaction<<endl;
    cout<<endl;
    
}

void totalSales(int small, int medium, int large)
{
    double totalCash;
    totalCash = (SMALL_CUP_COST * small) + (MEDIUM_CUP_COST * medium) + (LARGE_CUP_COST * large);
    cin>>totalCash;
    cout << "Total Sales are: " << showpoint << totalCash << endl;
    cout<<endl;
    
}

void totalCupsSold(int small, int medium, int large)

{
    double totalSmallOunces;
    double totalMediumOunces;
    double totalLargeOunces;
    double totalOunces;
   
    totalSmallOunces=small*small_Ouces;
    totalMediumOunces=medium*medium_Ounces;
    totalLargeOunces=large*large_Ounces;
    totalOunces=totalSmallOunces+totalMediumOunces+totalLargeOunces;
    cout<<"Total ounces of coffee sold "<<totalOunces<<endl;
    cout<<endl;
    
}

void sizesSold(int small, int  medium,int  large)
{
 
    cout << "Number of small cups of coffee sold: " << small << endl;
    cout << "Number of medium cups of coffee sold: " << medium << endl;
    cout << "Number of large cups of coffee sold: " << large << endl;
    cout<<endl;
   
}
closed account (D80DSL3A)
1
2
3
4
5
int choice = 0;
do
{
    // lines 45 - 68
}while( choice != 5 );
Last edited on
Thank you so much for your help!

I was able to finish the code and add in a few more things to make it look better.
Topic archived. No new replies allowed.