how do you use a data file already written with array

I've written a program which allow user to pick seats where they want.
and I wrote a data file which is "prices.dat" at priceFile function.
But I don't know how to use it to display how much user pay for the seats selected.
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
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

void priceFile(char seat[15][20]);

int main()
{

	const int ROW = 15;
	const int SEATS = 20;

	char avail = '*';
	char taken = '#';
	int choice,choiceRow,choiceSeat;

	char seats[ROW][SEATS];

	cout << "* Seats Available\n# Reserved Seats" << endl;
	cout << "Seats:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19";
	for(int i = 0; i < ROW; i++)
	{
		cout << "\nROW" << setw(3) << i;
		for(int index = 0; index < SEATS; index++)
		{
			seats[i][index] = avail;
			cout << setw(3) << seats[i][index];
		}
	}
	cout << "\n\nMENU:\n1) Buy ticket\n2) Total sell and exit" << endl;
	cout << "Enter your choice :";
	cin >> choice;
	
	while(choice == 1)
	{
		cout << "Enter row: ";
		cin >> choiceRow;
		cout << "Enter seat: ";
		cin >> choiceSeat;

		if(seats[choiceRow][choiceSeat] = avail)
		{
			seats[choiceRow][choiceSeat] = taken;
		}

		cout << "* Seats Available\n# Reserved Seats" << endl;
		cout << "Seats:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19";
		for(int i = 0; i < ROW; i++)
		{
			cout << "\nROW" << setw(3) << i;
			for(int index = 0; index < SEATS; index++)
			{
				cout << setw(3) << seats[i][index];
			}
		}
		cout << "\n\nMENU:\n1) Buy ticket\n2) Total sell and exit" << endl;
		cout << "Enter your choice :";
		cin >> choice;
	}
	if(choice ==2)
	{
		cout << "UPDATED SEATING CHART AND SALES INFO";
		cout << "* Seats Available\n# Reserved Seats" << endl;
		cout << "Seats:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19";
		for(int i = 0; i < ROW; i++)
		{
			cout << "\nROW" << setw(3) << i;
			for(int index = 0; index < SEATS; index++)
			{
				cout << setw(3) << seats[i][index];
			}
		}
		int sold = 0;
		for(int i = 0; i < ROW; i++)
		{
			for(int index = 0; index < SEATS; index++)
			{
				if(seats[i][index] == taken)
				{
					sold++;
				}
			}
		}
		cout << "\nTOTAL TICKET SOLD : " << sold;

		priceFile(seats);
		
		cout << "TOTAL REVENUE : $ ";


	
	}
}

void priceFile(char seat[15][20])
{
	int prices[15];
	string fname = "C://Users//User//Documents//Visual Studio 2010//Projects//prices.dat";
	ifstream outFile;
	outFile.open(fname.c_str());
	for(int i = 0; i < 15; i++)
	{
		if(i < 4)
		{
			prices[i] = 5;
			outFile >> prices[i];	
		}
		else if(i < 10)
		{
			prices[i] = 10;
			outFile >> prices[i];	
		}
		else if(i < 15)
		{
			prices[i] = 5;
			outFile >> prices[i];	
		}	
	}
	return;
}
Last edited on
Topic archived. No new replies allowed.