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
|
#include <iostream>
#include <iomanip> // <--- Added.
#include <string> // <--- Needed for the "std::string" and for some of the "cout" statements.
//#include <cmath> // <--- I see no use for this at this time.
#include <fstream>
using namespace std;
constexpr int MAXSIZE{ 25 }; // <--- You might want this as 26 for the arrays and another variable for for other places where you only want 25 characters in an array. The 26 gives you 1 more for the (\0) to mark the end of the string.
display_all() // <--- Needs a return type.
{
char name[MAXSIZE]{};
char hours[MAXSIZE]{};
char seats[MAXSIZE]{};
//fstream movie;
//movie.open("Movies.txt", ios::in);
// <--- But how do you know that it is open and usable?
int count = 0;
string line;
ifstream movie("Movies.txt"); // <--- The more preferred way to define and open a file stream.
// <--- But how do you know that it is open and usable?
while (getline(movie, line))
count++;
movie.clear();
movie.seekg(0);
int i = 0;
//while (movie.getline(name,MAXSIZE, '|') && movie.getline(seats, MAXSIZE, '|') && movie.getline(hours, MAXSIZE))
//while (movie.getline(name,MAXSIZE, '|'))
//while (!movie.eof() && i++ && i <= count)
while (!movie.eof(), i++, i <= count) // <--- Does not work the way that you are thinking. Esepically the ".eof()".
{
movie.getline(name, MAXSIZE, '|'); // <--- Delete line(s) used in the while loop.
movie.getline(seats, MAXSIZE, '|');
movie.getline(hours, MAXSIZE);
cout << "(" << i << ") " << name << "\n ";
//i++; // <--- Do here. Not in while condition.
}
return 0;
}
main() // <--- Needs a return type. Normally an "int".
{
char name[MAXSIZE]{}; // <--- All arrays would work better as a std::string.
char hours[MAXSIZE]{};
char seats[MAXSIZE]{};
char price[MAXSIZE]{};
char seats1[MAXSIZE]{};
char seats2[MAXSIZE]{};
char seats3[MAXSIZE]{};
char seats4[MAXSIZE]{};
char seats5[MAXSIZE]{};
char response = 'Y';
string customer, phone_number;
fstream movie;
movie.open("Movies.txt", ios::in);
char selection_role;
int selection_movie;
cout <<
" ***************************************************************\n"
" MOVIE TICKET RESERVATION SYSTEM (MTRS)\n"
" ***************************************************************\n\n\n";
//cout << endl << endl;
cout <<
" Please specify the selection:\n"
" (1) CUSTOMER\n"
" (2) MANAGEMENT\n\n";
//cout << endl;
cout << " INPUT: ";
cin >> selection_role;
if (selection_role == 1); // <--- The "if" statement ends with the (;) and does nothing.
cout << endl;
cout << "MOVIES AVAILABLE:\n "; // <--- Changed.
display_all();
//cout << '\n';
cout << "\nPlease select a movie: ";
cin >> selection_movie; // <--- I believe this value is 1 more than it should be.
int i = 0;
while (i++, i <= selection_movie) // <--- May not work the way that you are thinking.
{
movie.getline(name, MAXSIZE, '|');
movie.getline(seats, MAXSIZE, '|');
movie.getline(hours, MAXSIZE, '|');
movie.getline(price, MAXSIZE, '|'); // <--- Do not need the 3rd parameter here. Gives the variable the wrong number.
}
//cout << endl;
cout << "\n======You have selected " << name << ".=========\n"; // <--- Changed.
cout << endl;
cout << "Movie hours: " << seats << endl;
cout << "Number of seats available: " << hours << endl;
cout << " SCREEN " << endl << endl;
cout << " 1 2 3 4 5 6 7 8" << endl << endl; // <--- Changed. Added a leading space on the single digits for a better display.
cout << " 9 10 11 12 13 14 15 16" << endl << endl;
cout << "17 18 19 20 21 22 23 24" << endl << endl;;
cout << "25 26 27 28 29 30 31 32" << endl << endl;
cout << "Enter the number of seat you would like to book for: ";
cin >> seats1;
cout << endl;
cout << "Price for the ticket: RM " << price << endl << endl;
cout << "Enter you name: ";
cin >> customer;
cout << "Enter your phone number: ";
cin >> phone_number;
cout << endl;
cout << " MOVIE TICKET " << endl;
cout << "============================" << endl;
cout << "Name :" << customer << endl;
cout << "Handphone number :" << phone_number << endl;
cout << "Movie selected :" << name << endl;
cout << "Seat selected :" << seats1 << "," << seats2 << endl; // <--- No value for "seat2".
cout << "Price for the movie(RM):" << price << endl;
return 0; // <--- Not required, but makes a good break point.
}
|