Need help with theater seating problem



This is the code i have as of now.

include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>

using namespace std;
// function prototypes
float menu(int choice, int twoDArray[][30], float oneDArray[], float currentSales);
void loadSeats(int twoDArray[][30]);
void loadPrices(float oneDArray[]);
float displaySeatingChart(float[][30], float oneDArray[]);


//void savePrices(float [ ]) – Saves the current row prices to the file
//“rowPrices.dat”
//void saveSeats(char [ ][30]) – Save the current seating chart to the file
//“seatingChart.dat


int main()
// declaring variable
{
int choice = 0;
float currentSales = 0;
const int ARRAYCOLUMN = 30;
const int ARRAYROWS = 15;




float oneDArray[ARRAYROWS];
int twoDArray[ARRAYROWS][ARRAYCOLUMN];

// trying to load
// loading seats

loadSeats(twoDArray);
loadPrices(oneDArray);


// calling menu
choice = float(menu(currentSales, twoDArray, oneDArray, currentSales));




return 0;
}


float menu(int choice, float twoDArray[][30], float oneDArray[], float currentSales)

{

while (choice != 4)
{


cout << "*** Main Menu ***" << endl;
cout << "*** Sales This Session " << "<$" << currentSales << ">" << "***" << endl;

cout << "1. Display Seating Chart" << endl;
cout << "2. Purchase Tickets" << endl;
cout << "3. Change Ticket Prices" << endl;
cout << "4. Exit" << endl;
cout << "Enter Choice: ";
cin >> choice;


switch (choice)
{
case 1: displaySeatingChart(twoDArray, oneDArray);
break;

case 2:;
break;

case 3:;
break;

case 4: break;

default: cout << "*** Invalid Choice ***" << endl;
system("pause");
system("cls");
}
}


return float(choice);
}

//
void loadSeats(int twoDArray[][30])
{
const int ARRAYCOLUMN = 15;
const int ARRAYROWS = 30;

fstream seatingFile;
seatingFile.open("seatingChart.dat");

if (!seatingFile)
{
cout << "No Seating File Found. . . " << endl;
cout << "Clearing Seating Chart. . . " << endl;
system("pause");
system("cls");
for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
for (int columnNumber = 0; columnNumber < ARRAYROWS; columnNumber++)
{
twoDArray[rowNumber][columnNumber] = '#';
}
}
else
{
for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
for (int columnNumber = 0; columnNumber < ARRAYROWS; columnNumber++)
{
seatingFile >> twoDArray[rowNumber][columnNumber];
}
seatingFile.close();
}
}



// Loading Row Price File
void loadPrices(float oneDArray[])
{
const int ARRAYROWS = 15;

fstream priceFile;
priceFile.open("rowPrices.dat");

if (!priceFile)
{
cout << "No Price File Found. . . " << endl;
cout << "Setting Default Pricing to <$15 for each row>" << endl;
system("pause");
system("cls");

for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
oneDArray[rowNumber] = 15;

}
else
{
for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
priceFile >> oneDArray[rowNumber];

priceFile.close();
}
}

float displaySeatingChart(float twoDArray[][30], float oneDArray[])
{
float choice1 = 123;

for (int rownumber = 0; rownumber<15; rownumber++)
cout << "Row " << rownumber + 1 << right << setw(15) << setprecision(2) << oneDArray[rownumber + 1] << endl;

return choice1;
}

The error involves passing a float through an int, but i am having trouble figuring it out.

LNK2019 unresolved external symbol "float_cdecl menu(int,int(*const,float)" (?menu@@YAMHQAY0BO@HQAMM@Z) referenced in function_main
Last edited on
Use. Code. Tags.
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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>

using namespace std;
// function prototypes
float menu(int choice, int twoDArray[][30], float oneDArray[], float currentSales);
void loadSeats(int twoDArray[][30]);
void loadPrices(float oneDArray[]);
float displaySeatingChart(float[][30], float oneDArray[]);


//void savePrices(float [ ]) – Saves the current row prices to the file 
//“rowPrices.dat”
//void saveSeats(char [ ][30]) – Save the current seating chart to the file 
//“seatingChart.dat


int main()
// declaring variable
{
  int choice = 0;
  float currentSales = 0;
  const int ARRAYCOLUMN = 30;
  const int ARRAYROWS = 15;




  float oneDArray[ARRAYROWS];
  int twoDArray[ARRAYROWS][ARRAYCOLUMN];

  // trying to load 
  // loading seats

  loadSeats(twoDArray);
  loadPrices(oneDArray);


  // calling menu
  choice = float(menu(currentSales, twoDArray, oneDArray, currentSales));




  return 0;
}


float menu(int choice, float twoDArray[][30], float oneDArray[], float currentSales)

{

  while (choice != 4)
  {


    cout << "*** Main Menu ***" << endl;
    cout << "*** Sales This Session " << "<$" << currentSales << ">" << "***" << endl;

    cout << "1. Display Seating Chart" << endl;
    cout << "2. Purchase Tickets" << endl;
    cout << "3. Change Ticket Prices" << endl;
    cout << "4. Exit" << endl;
    cout << "Enter Choice: ";
    cin >> choice;


    switch (choice)
    {
      case 1:	displaySeatingChart(twoDArray, oneDArray);
        break;

      case 2:;
        break;

      case 3:;
        break;

      case 4: break;

      default: cout << "*** Invalid Choice ***" << endl;
        system("pause");
        system("cls");
    }
  }


  return float(choice);
}

// 
void loadSeats(int twoDArray[][30])
{
  const int ARRAYCOLUMN = 15;
  const int ARRAYROWS = 30;

  fstream seatingFile;
  seatingFile.open("seatingChart.dat");

  if (!seatingFile)
  {
    cout << "No Seating File Found. . . " << endl;
    cout << "Clearing Seating Chart. . . " << endl;
    system("pause");
    system("cls");
    for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
      for (int columnNumber = 0; columnNumber < ARRAYROWS; columnNumber++)
      {
        twoDArray[rowNumber][columnNumber] = '#';
      }
  } else
  {
    for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
      for (int columnNumber = 0; columnNumber < ARRAYROWS; columnNumber++)
      {
        seatingFile >> twoDArray[rowNumber][columnNumber];
      }
    seatingFile.close();
  }
}



// Loading Row Price File
void loadPrices(float oneDArray[])
{
  const int ARRAYROWS = 15;

  fstream priceFile;
  priceFile.open("rowPrices.dat");

  if (!priceFile)
  {
    cout << "No Price File Found. . . " << endl;
    cout << "Setting Default Pricing to <$15 for each row>" << endl;
    system("pause");
    system("cls");

    for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
      oneDArray[rowNumber] = 15;

  } else
  {
    for (int rowNumber = 0; rowNumber < ARRAYROWS; rowNumber++)
      priceFile >> oneDArray[rowNumber];

    priceFile.close();
  }
}

float displaySeatingChart(float twoDArray[][30], float oneDArray[])
{
  float choice1 = 123;

  for (int rownumber = 0; rownumber < 15; rownumber++)
    cout << "Row " << rownumber + 1 << right << setw(15) << setprecision(2) << oneDArray[rownumber + 1] << endl;

  return choice1;
}


Perhaps these will be a hint:
main.cpp(42): warning C4244: 'argument': conversion from 'float' to 'int', possible loss of data
main.cpp(42): warning C4244: '=': conversion from 'float' to 'int', possible loss of data

Your function returns a float but you're trying to store it in an int.

You have another problem, however, that I am surprised visual studio is not informing you of. You are going to overrun your array.

main.cpp(110): error C4789: buffer 'twoDArray' of size 1800 bytes will be overrun; 3600 bytes will be written starting at offset 0


And there's no need for you to include conio. Don't. Let it die.
Topic archived. No new replies allowed.