Function not returning value

Can someone help me find out why my function seatpurchase is not returning a value for me to use in another function. Once returned it is automatically 0. Please help my poor soul.... C++ till i die...

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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  #include <iostream>
#include <iomanip>


using namespace std;


const int COL = 30;


void write(char[][COL], int);
void display(char[][COL], int);
double Priceperrow(double [],int, int);
void availableseats(int, int, double, int);
int seatpurchase(char [][COL], int, int);
int seatpurchases(char [][COL], int, int);


int main()
{

    const int ROW = 15;
    char grid [ROW][COL];
    int answer = 0;
    double rowprices[ROW];
    int totalseats = ROW * COL;
    int purchaseforone = 0;
    int purchaseformany = 0;
    int priceforrow = 0;
    int purchase = 0;



    //screen clear u son of a bitch


    write (grid, ROW);
    display(grid, ROW);



        purchase = purchase + purchaseforone;

    do
    {


//Menu(answer);

        cout << "Welcome to the Theater Program" << endl;
        cout << endl;
        cout << "Menu" << endl;
        cout << endl;
        cout << "Are you a customer or a owner?" << endl;
        cout << "1.Customer" << endl
             << "2.Owner" << endl
             << "3.End" << endl;
        cin >> answer;




        if (answer == 1) //customer

        {
            cout << "Hello Customer" << endl;
            cout << endl;
            cout << "What would you like to do?" << endl;
            cout << "1.Purchase seats." << endl
                 << "2.Purchase Multiple seats" << endl
                 << "3.Program" << endl;
            cin >> answer;
            if (answer == 1) // purchase for seats
            {

                seatpurchase(grid, ROW, purchaseforone);
                cout << purchaseforone << endl;
This is the function that is not returning a value for me to use it inside available seats function.


            }

            else if (answer == 2) // multiple seats
            {
                seatpurchases(grid, ROW, purchaseformany);
            }

        }


        else if (answer == 2) // owner
        {
            cout << "Hello Owner" << endl;
            cout << endl;
            cout << "What would you like to do?" << endl;
            cout << "1.Price Input for seats." << endl
                 << "2.Show Availible Seats." << endl
                 << "3.End Program" << endl;
            cin >> answer;
            if (answer == 1) // price input for seats
            {
                Priceperrow(rowprices, ROW, priceforrow);
            }
            else if (answer == 2) // show availible seats
            {
                cout << purchaseforone << endl;

                availableseats(purchase,  purchaseformany ,rowprices[ROW] , totalseats);
            }

        }
        else if (answer == 3)
        {
            cout << "Goodbye" << endl;

            ;
            return 0;
        }



    }
    while (answer < 3);


    return 0;
}

void write(char grid [][COL], int rows)
{
    for(int x = 0; x<rows; x++)
    {
        for (int y = 0 ; y < COL; y++)
        {
            grid[x][y] = '#';
        }
    }

}

void display(char grid[][COL], int rows)
{
    int row = 1;
    cout <<"       123456789012345678901234567890" << endl;

    for(int x = 0; x<rows; x++)
    {
        cout  << "Row " << left << setw(3)<< row++;

        for (int y = 0 ; y < COL; y++)
        {
            cout << grid[x][y];
        }
        cout << endl;

    }

}

double Priceperrow(double ROW[], int row, int priceforrow)
{
    int numberofrow = 0;
    int rowcount = 0;
    double rowprice = 0;

    for( rowcount = 0; rowcount<row; rowcount++)
    {
        numberofrow++;
        cout << "Please Set the Price for Row " << numberofrow << endl;
        cin >> rowprice;

        ROW[rowcount] = rowprice;
        return ROW[rowcount];
    }

    return rowcount;
}

int seatpurchase(char ROWandColumn[][COL], int ROW, int Purchase)
{
    int Row = 0;
    int Seat = 0;





    cout << "What Row are you interested in?";
    cin >> Row;
    cout << "What seat are you interested in?";
    cin >> Seat;
    Row--;
    Seat--;
    Purchase = Purchase + 1;
    cout << Purchase;
   
    ROWandColumn[Row][Seat]= 'x';
    
    display(ROWandColumn, ROW);


return Purchase;
}
int seatpurchases(char firstset[][COL], int ROW, int purchase)
{
    int Row = 0;
    int Seat = 0;
    int answer = 0;




    {

        while (answer == 0)
        {
            cout << "How many seats are you buying?" << endl;
            cin >> answer;
        }
        for( int row = 0; row < answer; row++)
        {
            purchase++;

            cout << "What Row are you interested in for purchase " << purchase << "?"  << endl;
            cin >> Row;
            cout << "From what seat are you interested in purchase " << purchase << "?" << endl;
            cin >> Seat;

            Row--;
            Seat--;

            firstset[Row][Seat]= 'x';
        }

        display(firstset, ROW);
    }
    return purchase;
}

void availableseats(int soldseat, int soldseats, double profit, int totalseats)
{
    int totalseatssold = 0;
    int totalseatsleft = 0;

    //math
    totalseatssold = soldseat + soldseats;
    totalseatsleft = totalseats - totalseatssold;


    cout << "Total Seats Sold: " << totalseatssold << endl;

    cout << "Total Seats Open: " << totalseatsleft << endl;

    cout << "Total Profit: " << profit << endl;
}

//make equations in each function and return them to add here
Last edited on
The function is returning purchase, you are just not capturing the return by value.
Try defining function like this to return by reference:
int seatpurchases(char firstset[][COL], int ROW, int & purchase)

or use seatpurchases like this to return by value:
purchaseforone = seatpurchase(grid, ROW, purchaseforone );

Last edited on
I believe you are talking about the line
cout << purchaseforone << endl;

It returns 0 since variable purchaseforone is initialized as 0 and never changed. The return value of the function seatpurchase somehow is never printed in your code.

EDIT: I am slowing down.
Last edited on
I'm sorry I am still a beginner can you give me a more detailed answer please. I'm dyslexic.
At line 76
 
    seatpurchase(grid, ROW, purchaseforone);

the function is called, it returns a value, but the returned value is not stored or used anywhere.

You need to do something like this:
1
2
    int result = seatpurchase(grid, ROW, purchaseforone);
    cout << result;
or perhaps
 
    cout << seatpurchase(grid, ROW, purchaseforone);
Topic archived. No new replies allowed.