Not getting proper results.

So I am about 8 weeks into classes and this is the first time I've really been so confused and frustrated.

The task at hand is as follows:
Program must make use of files, arrays and functions.

The airplane will have 5 rows in the first class section with 4 seats in each row, 2 on each side of the aisle and 10 rows in the coach section with 3 seats on each side of the aisle. The prices for all the first class seats will be the same. The first 5 rows of coach will be more expensive than the last 5 rows. The prices for the seats will be stored in a file called SeatPrices.txt . The program should read these values from the file and store the values in an array of doubles.

This is easily my best work yet - and that's saying something considering how trash it probably is to most experienced authors. Every function (seemingly) works fine except for the most important one, which is gathering the prices from the .txt file and assigning them to the array (seatPrices[]) for use in my main function and otherwise.

I suspect largely that the issue arises somewhere in pricingInformation though from my inexperienced eyes I honestly don't see any glaring defects.
Any help/pointers in the right direction are greatly appreciated,
Thank you wise ones!

(I've had to remove a large chunk of the program due to post size constraints)

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
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>

using namespace std;

double pricingInformation();
void seatingChart();
void menu();
void menuSelect();
void seatingSold();
void seatRequests();
void seatReserving();
void fillChart();
void emptyRow();
void emptyPlane();
void displayTotalSales();
void checkRequests(int, int);

char firstClass[5][4];
char coach[5][6];
char economy[5][6];
double totalSales = 0;
double seatPrices[3];


int currentFirstClass, currentCoach, currentEconomy = 0;
int firstClassSold, coachSold, economySold = 0;

int main() 
{
	pricingInformation();
	fillChart();
	menu();

	system("pause");
	return 0;
}

double pricingInformation() 
{	
	int count = 0;

	ifstream file("SeatPrices.txt");
	if (file.is_open())
	{
		while (count < 3)
		{
			file >> seatPrices[count];
			count++;

		}
		file.close();
	}
	return seatPrices[count];
}

void fillChart() 
{
	for (int row = 0; row < 5; row++) 
	{
		for (int col = 0; col < 4; col++) 
		{
			firstClass[row][col] = '#';
		}
	}
	for (int row = 0; row < 5; row++) 
	{
		for (int col = 0; col < 6; col++) 
		{
			coach[row][col] = '#';
		}
	}
	for (int row = 0; row < 5; row++) 
	{
		for (int col = 0; col < 6; col++) 
		{
			economy[row][col] = '#';
		}
	}
}

void seatingChart() 
{
	cout << "Seating Chart" << endl;
	cout << "\t" << "1 2 3 4" << endl;

	for (int row = 0; row < 5; row++) 
	{
		cout << "Row " << (row + 1) << "\t";
		for (int col = 0; col < 4; col++) 
		{
			cout << firstClass[row][col] << " ";
		}
		cout << endl;
	}

	cout << "\t" << "123 456" << endl;
	for (int row = 0; row < 5; row++) 
	{
		cout << "Row " << (row + 6) << "\t";
		for (int col = 0; col < 6; col++) 
		{
			cout << coach[row][col];
			if (col == 2)
				cout << " ";
		}
		cout << endl;
	}

	for (int row = 0; row < 5; row++) 
	{
		cout << "Row " << (row + 11) << "\t";
		for (int col = 0; col < 6; col++) 
		{
			cout << economy[row][col];
			if (col == 2)
				cout << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void menu() 
{
	cout << "Main Menu" << endl << endl;
	cout << "1. Reserve seat(s)" << endl;
	cout << "2. Show me the seating chart." << endl;
	cout << "3. How many seats are sold?" << endl;
	cout << "4. How many seats are empty by row?" << endl;
	cout << "5. How many seats are empty on the plane?" << endl;
	cout << "6. Show me the total sales." << endl;
	cout << "7. Exit." << endl;

	cout << "What would you like to do? (enter 1 - 7): ";
	menuSelect();
	cout << endl;
}

void menuSelect() 
{
	const int
		RESERVE_SEAT = 1,
		SHOW_CHART = 2,
		SEATS_SOLD = 3,
		SEATS_EMPTY_ROW = 4,
		SEATS_EMPTY_PLANE = 5,
		TOTAL_SALES = 6,
		EXIT = 7;
	int choice;

	cin >> choice;
	cout << "-------------------------------------------";
	
	while (choice < RESERVE_SEAT || choice > EXIT) 
	{
		cout << "Please enter a valid menu choice (1 - 7): ";
		cin >> choice;
	}
	cout << endl;

	switch (choice) 
	{
	case RESERVE_SEAT:
		seatReserving();
		break;
	case SHOW_CHART:
		seatingChart();
		break;
	case SEATS_SOLD:
		seatingSold();
		break;
	case SEATS_EMPTY_ROW:
		emptyRow();
		break;
	case SEATS_EMPTY_PLANE:
		emptyPlane();
		break;
	case TOTAL_SALES:
		displayTotalSales();
		break;
	case EXIT:
		exit(0);
	}
	cout << "*******************************************" << endl;
	menu();
}

void seatReserving() 
{
	double currentTotal = 0;
	int numTickets;
	cout << "How many tickets would you like to reserve?: ";
	cin >> numTickets;
	cout << endl;
	for (int i = 0; i < numTickets; i++) 
	{
		seatRequests();
	}

	currentTotal = ((currentFirstClass * seatPrices[0]) + (currentCoach * seatPrices[1]) + (currentEconomy * seatPrices[2]));
	totalSales += currentTotal;
	cout << setprecision(2) << fixed << showpoint;
	cout << "Your total is $" << currentTotal << endl;

	currentTotal = 0;
	firstClassSold += currentFirstClass;
	coachSold += currentCoach;
	economySold += currentEconomy;
	currentFirstClass = currentCoach = currentEconomy = 0;
}

void seatingSold() 
{
	int totalseatingSold = firstClassSold + coachSold + economySold;
	cout << "There are " << totalseatingSold << " seats sold on the plane." << endl << endl
		<< "First Class Total: " << firstClassSold << endl
		<< "Coach Class Total: " << (coachSold + economySold) << endl
		<< "    Coach 1: " << coachSold << endl
		<< "    Coach 2: " << economySold << endl << endl;
}

void displayTotalSales() 
{
	double firstSales = firstClassSold * seatPrices[0];
	double coachSales = (coachSold * seatPrices[1]) + (economySold * seatPrices[2]);

	seatingSold();

	cout << setprecision(2) << fixed << showpoint;
	cout << "First Class Sales: $" << firstSales << endl
		<< "Coach Class Sales: $" << coachSales << endl << endl;
	cout << "The total sales is $" << totalSales << endl << endl;
}
/*
Course: CISS 241
Date: 4/23/2019
Assignment: #37
*/
There's no need for a function type double to read prices into an array. Just use a type void because the issue is with the return, also you have functions that have no definitions "seatRequests()", "emptyRow()", "emptyPlane()".
Hi nicholas, thanks for taking the time to reply.
Those functions are there in my full program, this is only a bit of the program (there's a post limit and the full program far exceeded the allowed 9000 characters)

Changing the double back to a void function still gives me the same results, which are no results at all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void pricingInformation() 
{	
	int count = 0;

	ifstream file("SeatPrices.txt");
	if (file.is_open())
	{
		while (count < 3)
		{
			file >> seatPrices[count];
			count++;
		}
		file.close();
	}
}
Verify that you have been able to open the file and read from it; emit some diagnostic information.

For example:

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

// ...
double seatprices[3] ;
// ...

bool read_pricing_information()
{
    const char file_name[] = "SeatPrices.txt" ;

    std::ifstream file(file_name);

    if( file.is_open() )
    {
        for( int i = 0 ; i < 3 ; ++i )
        {
            if( file >> seatprices[i] ) std::cout << "read price " << seatprices[i] << '\n' ;

            else
            {
                std::cout << "failed to read price from file '" << file_name << "'\n" ;
                return false ;
            }
        }

        std::cout << "successfully read prices from file '" << file_name << "'\n" ;
        return true ;
    }

    else
    {
        std::cout << "unable to open seat prices file '" << file_name << "'\n" ;
        return false ;
    }
}

int main()
{
    if( !read_pricing_information() )
    {
        std::cout << "pricing file read failure. quitting program.\n" ;
        return 1 ;
    }

    // ...
}
Topic archived. No new replies allowed.