Returning value to main

Hi, I'm trying to create my first program however, I ran into a deadend. I want to send the value from the switch statement all the way to main. I've tried using return statements, but I don't think that's the right way to do it.
I hope that made sense.

Any help is appreciated, thanks.

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
/*
A program which runs a simple restaurant order.
*/
#include <iostream>
using namespace std;

void menu()
{
    void drink();
    int choice;
    int burger = 15.00;
    int wings = 7.00;
    int steak = 16.50;
    int stew = 11.00;
    int sub = 14.00;

    cout << endl;
    cout << "Here's the menu please decide what you'd like.\n";
    cout << "1. Classic Joe Burger: 15.00\n";
    cout << "2. Buffalo Wings: 7.00\n";
    cout << "3. Classic Joe Steak: 16.50\n";
    cout << "4. Beef Stew: 11.00\n";
    cout << "5. Supreme Sub: 14.00\n\n";
    cout << "What is your choice: ";
    cin >> choice;

    switch (choice)
        {
            case 1:
            cout << "You chose the Classic Joe Burger! What would you like to drink?\n";
            return burger;
            drink();
            break;

            case 2:
            cout << "You chose the Buffalo Wings! What would you like to drink?\n";
            return wings;
            drink();
            break;

            case 3:
            cout << "You chose the Classic Joe Steak! What would you like to drink?\n";
            return steak;
            drink();
            break;

            case 4:
            cout << "You chose the Beef Stew! What would you like to drink?\n";
            return stew;
            drink();
            break;

            case 5:
            cout << "You chose the supreme sub! What would you like to drink?\n";
            return sub;
            drink();
            break;

            default:
            cout << "That's not on the menu!";
        }

}

void drink()
{
        int beer = 5.50;
        int choice2;

        cout << "Here is the list of Beers available. Each bottle is 5.50.\n";
        cout << endl;
        cout << "1. Budweiser\n";
        cout << "2. Heineken\n";
        cout << "3. Efes Pilsen\n";
        cout << "4. Corona Extra\n";
        cout << "5. San Miguel Pale Pilsen\n";
        cout << "6. Guinness\n";
        cout << "7. Miller Lite\n";
        cout << endl;
        cout << "What is your choice: ";
        cin >> choice2;

        switch(choice2)

        {


            case 1:
            cout << "You chose the Budweiser.";
            return beer;
            break;

            case 2:
            cout << "You chose the Heineken.";
            return beer;
            break;

            case 3:
            cout << "You chose the Efes Pilsen.";
            return beer;
            break;

            case 4:
            cout << "You chose the Corona Extra.";
            return beer;
            break;

            case 5:
            cout << "You chose San Miguel Pale Pilsen.";
            return beer;
            break;

            case 6:
            cout << "You chose Guinness.";
            return beer;
            break;

            case 7:
            cout << "You chose Miller Lite.";
            return beer;
            break;

            default:
            cout << "I'm sorry but that was not a choice.";

        }
}

int main()
{

char o;

    cout << "Welcome to Joe's Restaurtant & bar!\n";
    cout << "Would you like to order?.\n";
    cout << "Y/N? ";
    cin >> o;
    if (o == 'Y')
    menu();

    else if (o == 'N')
    cout << "Oh, Goodbye.\n";

    else
    cout << "I don't understand.\n";

    cout << "Your total comes out to: $" << choice + beer << ". Please enjoy your meal!";

    return 0;
}






Last edited on
You routines are listed as void meaning they do not return and datatypes that you can use.

Change the void to whatever datatype you want to return. Since Beer and Stew are both ints change their headings to

int menu() & int drink()


Edit - Why are you declaring the drink(); routine inside the menu routine on line 9? Instead declare int menu(); and int drink; at the very top of your file and then move their implementation down below your main.

Good luck.
Last edited on
Ahh, it compiles now. Thanks!

Edit - Egh, the program doesn't work right, but I'll try your edited fix.

Edit2 - Got it. Now I can play around some more. Thank you!
Last edited on
Topic archived. No new replies allowed.