I am currently stuck on what I think is a very small problem. I'm currently in my second semester of comp sci and am pretty new to programming. I am sorry if this is a dumb question, but I cannot figure out why I am getting an output of 37 '.''s when there are clearly 36.
Our project is to create a movie theater ticketing system that has a final report showing the amount of ticket sales. We have to show reserved and open seats. The reserved seats work fine, but the open seats always display 1 more than there actually are.
In the function getSeatInfo, reservedSeats and openSeats are passed by reference. I believe they are automatically updated when the function runs to the final report function. When I use while(fs >> data) to go through the whole file correctly, it says that I have either half (if I use char data;) or none (if I use anything else). I can't figure it out.
Here is the file I am accessing. I am using "A1.txt" as a test key for my file stream.
............#.##
.....####.#....#
###.....#.#.###.
#...#.###.###...
#########.....##
Can someone take a look at this please? Thanks!
void finalReport() { // Function to print the end of days statistics
for(int i = 1; i <= 3; i++) {
string auditorium;
switch(i) {
case 1: auditorium = "A1.txt";
break;
case 2: auditorium = "A2.txt";
break;
case 3: auditorium = "A3.txt";
break;
}
int reservedSeats = 0, openSeats = 0;
getSeatInfo(auditorium, reservedSeats, openSeats);
int totalSales = reservedSeats * 7;
cout << "Auditorium " << i << ": " << " Reserved Seats: " << reservedSeats << " Open Seats: " << openSeats << " Total Sales: " << totalSales << endl;
}
}
void getSeatInfo(string auditorium, int& reservedSeats, int& openSeats) {
fstream fs;
char currentChar;
fs.open(auditorium, ios::in);
while(!fs.eof()) {
fs.get(currentChar);
if(currentChar == '.') {
reservedSeats += 1;
}
else if(currentChar == '#') {
openSeats += 1;
}
}
fs.close();
}
This is the output I am getting:
Auditorium 1: Reserved Seats: 44 Open Seats: 37 Total Sales: 308
Auditorium 2: Reserved Seats: 0 Open Seats: 0 Total Sales: 0
Auditorium 3: Reserved Seats: 0 Open Seats: 0 Total Sales: 0