String Array

Pages: 12
Hello. I am a beginner in C++. I am doing a coding where there will be a menu for selection and after selecting the food the user want, it will be shown in a receipt above. The food and drink list is in the text file. I copy paste the data in Foods.txt for understanding. The thing is that the program is just copying one data into the receipt. I cannot add two or more data into it. Can anyone help me to solve it?

Example in Foods.txt

Mee hoon|8.00
Nasi Lemak|9.00
Popcorn|7.00
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
  food_drinks()
 {
     system("CLS");
     title();
     fstream foods, drinks;
     char food[25], drink[25], price[25], price_1[25];
     string display1[25];
     string display2[25];
     string display3[25];
     string food1, price_a, drink1, price_b, quantity2;
     int resp1, y, resp, p = 1;
     float quantity, total_price;
     cout <<" Welcome to snacks and drinks section !!! " << endl << endl;

     menu:
     foods.open("Food.txt",ios::in);
     drinks.open("Drink.txt",ios::in);
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                            SNACKS AND DRINKS                                                      | " << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                      SNACKS AVALABLE                   |   PRICE   |                    DRINKS AVAILABLE              |   PRICE   |" << endl;
     cout << "|----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                        |           |                                                  |           |" << endl;
     int i = 0, food1_length, pricea_length, drink1_length, priceb_length;
     while (i++, i <= 9 )
     {
         foods.getline(food,25,'|');
         foods.getline(price,25);
         drinks.getline(drink,40,'|');
         drinks.getline(price_1,25);
         food1 = food;
         price_a = price;
         drink1 = drink;
         price_b = price_1;
         food1_length = food1.length();
         pricea_length = price_a.length();
         drink1_length = drink1.length();
         priceb_length = price_b.length();

         cout <<"| (" << i <<")     " << food;
          int y = food1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "                     | RM " <<  price ;

          y = pricea_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 6);

          cout <<"| (" << i <<")     " << drink;

          y = drink1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "               | RM " <<  price_1 ;

          y = priceb_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 6);

          cout <<"|" << endl;
     }
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl << endl;
     cout << " [Food = 1 || Drink = 2 ]" << endl;
     cout << " Do you want to select food or drink = " ;
     cin >> resp;
     cout << " Select the number of food you would like to order: ";
     cin >> resp1;
     cout << " Specify the quantity of selected food to purchase: ";
     cin >> quantity;
     foods.close();
     drinks.close();

     do
     {
     system("CLS");
     foods.open("Food.txt",ios::in);
     drinks.open("Drinks.txt",ios::in);
     title();
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                            YOUR RECEIPT                                                          | " << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                   ITEM                                                    | QUANTITY |   PRICE   |" << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl ;

      int a = 1;
      while(a <= p)
    {
     i = 0;
     if (resp == 1)
     {
        while (i++, i <= resp1 )
        {
         foods.getline(food,25,'|');
         foods.getline(price,25);
        }

        food1 = food;
        display1[p] = food;
        fstream temp;
        temp.open("temp.txt",ios::out);
        temp << quantity;
        temp.close();
        char quantity1[25];
        temp.open("temp.txt",ios::in);
        temp.getline(quantity1,25);
        temp.close();
        remove("temp.txt");
        quantity2 = quantity1;
        display2[p] = quantity1;
        price_a = price;
        food1_length = food1.length();
        pricea_length = price_a.length();
     }

     else
     {
         while (i++, i <= resp1 )
        {
         drinks.getline(drink,25,'|');
         drinks.getline(price_1,25);
        }

        drink1 = drink;
        display1[p] = food;
        fstream temp;
        temp.open("temp.txt",ios::out);
        temp << quantity;
        temp.close();
        char quantity1[25];
        temp.open("temp.txt",ios::in);
        temp.getline(quantity1,25);
        temp.close();
        remove("temp.txt");
        quantity2 = quantity1;
        display2[p] = quantity1;
        price_b = price_1;
        drink1_length = drink1.length();
        priceb_length = price_b.length();
     }
          float price1 = std::atof(price);
          cout <<"| (" << a <<")     " << display1[p];
          int y = food1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "                                                                        | " <<  display2[p] << "   ";
          int quantity_length = quantity2.length();
          total_price = quantity * price1;
          fstream temp;
          temp.open("temp.txt",ios::out);
          temp << total_price;
          temp.close();
          char total_price1[25];
          temp.open("temp.txt",ios::in);
          temp.getline(total_price1,25);
          temp.close();
          remove("temp.txt");
          string total_price2 = total_price1;
          display3[p] = total_price1;

          y = quantity_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 5);
          cout << "    | " <<  display3[p] ;
          int totalprice1_length = total_price2.length();

          y = totalprice1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 5);
          cout << "       |" << endl;
          a = a+1;

    }
       foods.close();
       drinks.close();

       cout << endl << endl;
       i = 0;
       goto menu;
       p = p + 1;
    }while(y = 1);

}
Last edited on
Hello Mathavan,

It is best to provide a complete program that can be compiled and run.

If you are writing the code for the compiler then you have to much white space in your code.

If you want someone to read it, and you do, you need some blank lines to break up the code.

Try to avoid using "goto"s in a program. They still have a rare use, but not for general code.

It will take me a little time to get your code running so I can see what it is doing.

Andy
If all you want is a menu showing the food and price from food.txt and drinks from drink.txt, ask the use to select food/drink (s) and then display what has been chosen and the price then your code is vastly over-complicated. It can be much simpler. When I get some time, I'll knock up some demo/test code.
Hello Mathavan,

When I got the program to compile and run I found this output:

 Welcome to snacks and drinks section !!!

 -----------------------------------------------------------------------------------------------------------------------------------
|                                                            SNACKS AND DRINKS                                                      |
 -----------------------------------------------------------------------------------------------------------------------------------
|                      SNACKS AVALABLE                   |   PRICE   |                    DRINKS AVAILABLE              |   PRICE   |
|-----------------------------------------------------------------------------------------------------------------------------------
|                                                        |           |                                                  |           |
| (1)                                                    | RM        | (1)                                              | RM        |
| (2)                                                    | RM        | (2)                                              | RM        |
| (3)                                                    | RM        | (3)                                              | RM        |
| (4)                                                    | RM        | (4)                                              | RM        |
| (5)                                                    | RM        | (5)                                              | RM        |
| (6)                                                    | RM        | (6)                                              | RM        |
| (7)                                                    | RM        | (7)                                              | RM        |
| (8)                                                    | RM        | (8)                                              | RM        |
| (9)                                                    | RM        | (9)                                              | RM        |
 -----------------------------------------------------------------------------------------------------------------------------------

 [Food = 1 || Drink = 2 ]
 Do you want to select food or drink =


As you can see there is nothing there because the files did not open, but the program continued as if it had.

Every time you open a file you need to check that it opened. That is for both input and output. Otherwise your program will continue without being able to read from the file.

Your program needs 2 input files, but you only provided 1. Please post an example of the drink file.

Looking at you program I would suggest that you prefer to use (\n) in place of all those (endl)s. In the places where you have 2 "endl"s you can use ("\n\n").

Unless you have a need for "float" prefer to use "double".

Using "fstream" is fine, but you also have the choice of "ifstream" and "ofstream". Since they already imply input and output there is no need to use "std::ios::in".

Not sure what to do with the drink file, but I will come up with something.

Just a note: in your input file you use the (|) as a delimiter, but more often the (,) comma is used. Eventually you will have to deal with a CSV, (Comma Seperated Value), file. You may find it better to get use to this early and leave other delimiter characters for something special. Just a thought.

Andy
Thanks for the reply. Is there any way to attach my cpp file so that you can have a better understanding of my coding?
Hello Mathavan,

Yes. You can do what you did in your first post unless the code is vary large then you may need 2 posts or leave out what you have already posted or use something line Paste Bin.

I did not see seeplus's reply until after I posted, but if you wait long enough you will get a program the is better than what you have and you will have less work to do.

I will say this, what you send to the screen is to wide. On a laptop the lines will wrap making it hard to read. I have a large screen and it comes close to not fitting when I maximize the console window.

When you read your files you should read them into parallel arrays or create a struct and have 1 array of structs. This will save you from having read the file each time you need something.

Andy
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

//Program Description: MTRS, Movie Ticket Reservation System

#include <iostream>
#include <fstream>
#include <iomanip>
#include <limits>
#include <ctime>
#include <cstdlib>

/* code table   0 = Black       8 = Gray
 1 = Blue        9 = Light Blue
 2 = Green       A = Light Green
 3 = Aqua        B = Light Aqua
 4 = Red         C = Light Red
 5 = Purple      D = Light Purple
 6 = Yellow      E = Light Yellow
 7 = White       F = Bright White */
#include<dos.h>

using namespace std;

int selection_movie;

void title()
{
            cout << "                  *************************************************************************************************"       << endl;
            cout << "                                              MOVIE TICKET RESERVATION SYSTEM (MTRS)                               "       << endl;
            cout << "                  *************************************************************************************************"       << endl << endl;
}

void showmovielist()
{
    char name [25];
    char time1[25];
    char time2[25];
    char time3[25];

    system("CLS");
    fstream movie;
    movie.open("Movies.txt",ios::in);

    int count = 0;
    string line;

    ifstream file("Movies.txt");
     while (!file.eof())
    {
        getline(file, line);
        count++;
    }

    count = count - 1;

    title();
    cout << "======================================================================================================================" << endl;
    cout << "|SERIAL NUMBER|               TIME[SHOW1]              TIME[SHOW2]              TIME[SHOW3]            |MOVIE NAME|   " << endl;
    cout << "======================================================================================================================" << endl;
    int i = 0;
    while(i++ , i<= count)
    {
        movie.getline(name,25,'|');
        movie.getline(time1,25,'|');
        movie.getline(time2,25,'|');
        movie.getline(time3,25);
        cout << "    (" << i << ") " << "\t\t\t " << time1 << "\t\t\t " << time2 << "\t\t\t " << time3 << "\t\t\t " << name << "\n";
    }
}

void add_movie()
{
    system("CLS");
    char name [25];
    int time1;
    int time2;
    int time3;

    fstream movie;
    movie.open("Movies.txt",ios::app);

    title();
    cout << "Adding new movie!!";
    cout << endl << endl;
    cin.ignore();
    cout << " Enter the movie name: ";
    cin.getline(name,25);
    cout << " Enter the time for First show  (HHMM): ";
    cin >> time1;

    while(!cin >> time1)
    {
        cout << endl;
        cout << " Enter a valid time: " ;
        cin.clear();
        cin.ignore(25,'\n');
        cin >> time1;
    }

    while((time1 > 2400) || (time1 < 0))
    {
        cout << endl;
        cout << " You have entered a wrong time for movie. Enter again!!"<< endl;
        cout << " Enter the time for First show  (HHMM): ";
        cin >> time1;
    }

    cout << endl;
    cout << " Enter the time for Second show (HHMM): ";
    cin >> time2;

     while(!cin >> time2)
    {
        cout << endl;
        cout << " Enter a valid time: " ;
        cin.clear();
        cin.ignore(25,'\n');
        cin >> time2;
    }


    while((time2 > 2400) || (time2 < 0))
    {
        cout << endl;
        cout << " You have entered a wrong time for movie. Enter again!!"<< endl;
        cout << " Enter the time for Second show  (HHMM): ";
        cin >> time2;
    }

    cout << endl;
    cout << " Enter the time for Third show  (HHMM): ";
    cin >> time3;

    while(!cin >> time3)
    {
        cout << endl;
        cout << " Enter a valid time: " ;
        cin.clear();
        cin.ignore(25,'\n');
        cin >> time3;
    }

    while((time3 > 2400) || (time3 < 0))
    {
        cout << endl;
        cout << " You have entered a wrong time for movie. Enter again!!"<< endl;
        cout << " Enter the time for Third show  (HHMM): ";
        cin >> time3;
    }

    movie << name << '|' << time1 << '|' << time2 << '|' << time3;
    cout << endl << endl;
    cout << "You are done, Manager!";
    movie.close();
}

void delete_movie()

{
    fstream movie;
    fstream temp;
    int lines;
    char selection_movie1;
    char name [25];
    char time1[25];
    char time2[25];
    char time3[25];

    movie.open("Movies.txt",ios::in);
    temp.open("temp.txt",ios::out);

    cout << endl;
    cout << "Enter the serial number of the movie that you want to delete [1,2,3...] : ";
    cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
    cin >> selection_movie1;

    char count = '0';
    string line;

    ifstream file("Movies.txt");
    while (!file.eof())
    {
        getline(file, line);
        count++;
    }

    lines = count - 51 ;

    while((selection_movie1 <= '0') || (selection_movie1 > count))
    {
        cout << endl;
        cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
        cout << "Please select a movie: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> selection_movie1;
    }

    selection_movie = (selection_movie1 - 48);

    int i = 0;
    while(i++ , i <= count)
    {
        movie.getline(name,25,'|');
        movie.getline(time1,25,'|');
        movie.getline(time2,25,'|');
        movie.getline(time3,25);

        if (i == selection_movie)
        {
            continue;
        }
        else
        {
            temp << name << '|' << time1 << '|' << time2 << '|' << time3 <<'\n';
        }
    }
    temp.close();
    movie.close();

    movie.open("Movies.txt",ios::out);
    temp.open("temp.txt",ios::in);

    int y = 0;
    do
    {
        temp.getline(name,25,'|');
        temp.getline(time1,25,'|');
        temp.getline(time2,25,'|');
        temp.getline(time3,25);
        movie << name << '|' << time1 << '|' << time2 << '|' << time3 << '\n';
        y = y + 1;
    }while (y <= lines);

    temp.close();
    movie.close();
    remove("temp.txt");
    cout << "\n done !!! \n";

}

void temp_movie()
{
    fstream movie;
    movie.open("Movies.txt",ios::in);
    char name [25];
    char time1[25];
    char time2[25];
    char time3[25];

    int i = 0;
    while(i++ ,i <= selection_movie)
    {
        movie.getline(name,25,'|');
        movie.getline(time1,25,'|');
        movie.getline(time2,25,'|');
        movie.getline(time3,25);
    }
    cout << endl;
    cout << "============== You have selected " << name << ".=====================" << endl;
}

void update_movie()
{
    fstream movie;
    fstream temp;
    int lines;
    char selection_movie1;

    movie.open("Movies.txt",ios::in);
    temp.open("temp.txt",ios::out);
    char name [25];
    char time1[25];
    char time2[25];
    char time3[25];
    cin.ignore();
    cout << endl;
    cout << "Enter the serial number of the movie that you want to update [1,2,3...]: ";
    cin >> selection_movie1;

    char count = '0';
    string line;

   ifstream file("Movies.txt");
    while (!file.eof())
    {
        getline(file, line);
        count++;
    }

    lines = count - 50 ;

    while((selection_movie1 <= '0') || (selection_movie1 > count))
    {
        cout << endl;
        cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
        cout << "Please select a movie: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> selection_movie1;
    }

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
244
245
246
247
248
249
250
251

    selection_movie = (selection_movie1 - 48);

    temp_movie();
    cout << endl;

    int i = 0;
    while(i++ , i <= count)
    {
        movie.getline(name,25,'|');
        movie.getline(time1,25,'|');
        movie.getline(time2,25,'|');
        movie.getline(time3,25);

        if (i == selection_movie)
        {
            int time_a, time_b, time_c;
            cout << " Enter the time for First show (HHMM): ";
            cin >> time_a;

            while(!cin >> time_a)
            {
                cout << endl;
                cout << " Enter a valid time: " ;
                cin.clear();
                cin.ignore(25,'\n');
                cin >> time_a;
            }


            while((time_a > 2400) || (time_a < 0))
            {
                cout << endl;
                cout << "You have entered a wrong time for movie. Enter again!!"<< endl;
                cout << " Enter the time for First show  (HHMM): ";
                cin >> time_a;
            }

                cout << " Enter the time for Second show (HHMM): ";
                cin >> time_b;

            while(!cin >> time_b)
            {
                cout << endl;
                cout << " Enter a valid time: " ;
                cin.clear();
                cin.ignore(25,'\n');
                cin >> time_b;
            }


            while((time_b > 2400) || (time_b < 0))
            {
                cout << endl;
                cout << "You have entered a wrong time for movie. Enter again!!"<< endl;
                cout << " Enter the time for Second show  (HHMM): ";
                cin >> time_b;
            }

            cout << endl;
            cout << " Enter the time for Third show  (HHMM): ";
            cin >> time_c;

            while(!cin >> time_c)
            {
                cout << endl;
                cout << " Enter a valid time: " ;
                cin.clear();
                cin.ignore(25,'\n');
                cin >> time_c;
            }

            while((time_c > 2400) || (time_c < 0))
            {
                cout << endl;
                cout << "You have entered a wrong time for movie. Enter again!!"<< endl;
                cout << " Enter the time for Third show  (HHMM): ";
                cin >> time_c;
            }
            temp << name << '|' << time_a << '|' << time_b << '|' << time_c << '\n';
        }

        else
        {
            temp << name << '|' << time1 << '|' << time2 << '|' << time3 << '\n';
        }

    }
    temp.close();
    movie.close();

    movie.open("Movies.txt",ios::out);
    temp.open("temp.txt",ios::in);

    int y = 0;
    do
    {
        temp.getline(name,25,'|');
        temp.getline(time1,25,'|');
        temp.getline(time2,25,'|');
        temp.getline(time3,25);
        movie << name << '|' << time1 << '|' << time2 << '|' << time3 << '\n';
        y = y + 1;
    }while (y <= lines);

    temp.close();
    movie.close();

    cout << "\n You have done editing the showtime manager!!! \n";
    remove("temp.txt");
}

management()
{
    {
        system("CLS");

        title();
        string userName;
        string userPassword;
        int loginAttempt = 0;

        cout << endl << endl;
        while (loginAttempt < 5)
        {
            cout << "Please enter your user name: ";
            cin >> userName;
            cout << "Please enter your user password: ";
            cin >> userPassword;

            if (userName == "Mathavan" && userPassword == "MTRS")
            {
                cout << "Welcome Mathavan!" << endl;
                break;
            }
            else if (userName == "Sofea" && userPassword == "MTRS")
            {
                cout << "Welcome Sofea!" << endl;
                break;
            }
            else if (userName == "Nicole" && userPassword == "MTRS")
            {
                cout << "Welcome Nicole!" << endl;
                break;
            }
            else if (userName == "Weishan" && userPassword == "MTRS")
            {
                cout << "Welcome Weishan!" << endl;
                break;
            }
            else if (userName == "Winston" && userPassword == "MTRS")
            {
                cout << "Welcome Winston!" << endl;
                break;
            }
            else
            {
                cout << "Invalid login attempt. Please try again.\n" << '\n';
                loginAttempt++;
            }
        }
        if (loginAttempt == 5)
        {
            cout << "Too many login attempts! The program will now terminate.";
            return 0;
        }

        bool flag=true;
        while (flag)
        {
            system("CLS");
            title();
            cout << endl << endl << endl;
            cout << "                                          (1) Enter a new movie " << endl << endl << endl;
            cout << "                                          (2) Update the showtime for a movie" << endl << endl << endl;
            cout << "                                          (3) Delete a movie " << endl << endl << endl;

            char c;
            cout << "Enter your selection manager: ";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> c;

            switch (c)
            {
                case '1' :
                    add_movie();
                    break;
                case '2':
                    showmovielist();
                    update_movie();
                    break;
                case '3':
                    showmovielist();
                    delete_movie();
                    break;

                default :
                cout << endl;
                cout << "Please input a correct selection\n";
                cout << "If you continue to use program press ' y ',if no please press any input to restart\n ";
            }
                cout << " if you continue to use program press ' y ' \n ";
                char f;
                cin >> f;
                if(f!='y')
                {
                    flag=false;
                }
        }

    }
}

membership()
{
    char resp;

    system("CLS");
    title();
    cout << endl;
    cout << "                  ========================            ==========================          ==========================     " << endl;
    cout << "                  * (A)    NEW MEMBER    *            * (B)  RENEW MEMBERSHIP  *          * (C) MEMBER INFORMATION *     " << endl;
    cout << "                  ========================            ==========================          ==========================     " << endl << endl;
    cout << "                                                                Input :" ;
    cin >> resp;

    while ((resp != 'A') && (resp != 'B') && (resp != 'C') && (resp != 'a') && (resp != 'b') && (resp != 'c'))
    {
        cout << endl;
        cout << "Enter a valid response: ";
        cin >> resp;
    }

    if (resp == 'A' || resp == 'a')
    {
        fstream member;
        member.open("Membership.txt",ios::app);
        string icno, name, email, phone_number;
        int length, name_length, valid_email = 0, email_length, phone_length, acc_num;
        char temp;

        system("CLS");
        title();

        cout << "                                                   WELCOME TO THIS CINEMA !!                                       "       << endl << endl;
        cout << "                                   We are glad on your interest to be a part of our family                         "       << endl << endl << endl;
        cout << "                  Enter your name: ";
        cin >> name;
        cout << endl;
        cout << "                  Enter your Identification Number(IC) without dash (-) : ";
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
       cin >> icno;

        name_length = name.length();
        length = icno.length();

        while (length != 12)
        {
          cout << endl;
          cout << "                 Enter a valid IC Number: ";
          cin >> icno;
          length = icno.length();
        }

        int gender = (icno.at(11));
        gender = gender % 2;

        cout << endl ;
        cout << "                  Enter your email address: ";
        cin >> email;
        cout << endl;

        email_length = email.length();

        for (int i=0; i<email.length(); ++i)
        {
            temp = email.at(i);
            if (temp == '@' )
            {
                valid_email = 1;
            }
        }

        while (valid_email != 1)
        {
           cout << "               Enter a valid email address: ";
           cin.ignore();
           cin >> email;
           cout << endl;

           for (int i=0; i<email.length(); ++i)
           {
            temp = email.at(i);
            if (temp == '@' )
            {
                valid_email = 1;
            }
           }
        }

        cout << "                  Enter your phone number : ";
        cin >> phone_number;

        phone_length = phone_number.length();

        while (phone_length != 10)
        {
          cout << endl;
          cout << "                Enter a valid phone number: ";
          cin >> phone_number;
          length = phone_number.length();
        }

        details:
        system("CLS");

        title();
        cout << endl;
        cout << " ---------------------------------------------------------------------------------------------------------------------------------- " << endl;
        cout << "|                                                                                                                                  |" << endl;
         if (gender == 1)
        {
          cout << "|                   Hello Mr " << name << " ,";

          int y = name_length;

          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);

        }

         else
        {
          cout << "|                   Hello Ms " << name << " ,";

          int y = name_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        }

        cout << "                                                 |" << endl ;
        cout << "|                                                                                                                                  |" << endl;
        int i = 5;
        cout << "|                   Your birthday is " << icno.at(i-1) << icno.at(i) << " - " << icno.at(i-2) << icno.at(i-3) << " - " << icno.at(i-5) << icno.at(i-4) << "                                                                                  |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Identification Number : " << icno;

        int y = length ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);

        cout << "                               |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Email Address : " << email;
        y = email_length ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);

        cout << "                                       |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Phone Number : " << phone_number;
        y = phone_length ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        cout << "                                        |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << " ---------------------------------------------------------------------------------------------------------------------------------- " << endl << endl;
        cout << "                                         WOULD YOU LIKE TO CONFIRM YOUR DETAILS [Y/N] : ";
        cin >> resp;

        while ((resp != 'Y') && (resp != 'y') && (resp != 'N') && (resp != 'n') )
        {
            cout << endl;
            cout << "Enter a valid response: ";
            cin >> resp;
        }

        if (resp == 'N' || resp == 'n')
        {
            system("CLS");
            title();
            cout << endl;
            cout << "                                               WHICH DATA YOU WOULD LIKE TO CHANGE :                               "       << endl << endl;
            cout << "                                                  (A) NAME"                  << endl << endl;
            cout << "                                                  (B) IDENTIFICATION NUMBER" << endl << endl;
            cout << "                                                  (C) EMAIL ADDRESS        " << endl << endl;
            cout << "                                                  (D) PHONE NUMBER         " << endl << endl;
            cout << "                                              Enter your response:         " ;
            cin >> resp;

            while ((resp != 'a') && (resp != 'A') && (resp != 'B') && (resp != 'b') && (resp != 'C') && (resp != 'c') && (resp != 'D') && (resp != 'd') )
            {
              cout << endl;
              cout << "Enter a valid response: ";
              cin >> resp;
            }

            cout << endl << endl;
            if (resp == 'A' || resp == 'a')
            {
                cout << "Enter your name: ";
                cin >> name;
                goto details;
            }

            else if (resp == 'B' || resp == 'b')
            {
                cout << "Enter your Identification Number: ";
                cin >> icno;
                length = icno.length();

                while (length != 12)
                {
                    cout << endl;
                    cout << "                  Enter a valid IC Number: ";
                    cin >> icno;
                    length = icno.length();
                }

                int gender = (icno.at(11));
                gender = gender % 2;
                goto details;
            }

            else if (resp == 'C' || resp == 'c')
            {
                cout << "Enter your Email Adress: ";
                cin >> email;

                email_length = email.length();

                for (int i=0; i<email.length(); ++i)
                {
                    temp = email.at(i);
                    if (temp == '@' )
                    {
                        valid_email = 1;
                    }
                }

            while (valid_email != 1)
            {
                cout << "               Enter a valid email address: ";
                cin.ignore();
                cin >> email;
                cout << endl;

                for (int i=0; i<email.length(); ++i)
                {
                    temp = email.at(i);
                    if (temp == '@' )
                    {
                        valid_email = 1;
                    }
                }
            }

            goto details;
            }

            else
            {
                cout << "Enter your phone number : ";
                cin >> phone_number;

                phone_length = phone_number.length();
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
while (phone_length != 10)
                {
                    cout << endl;
                    cout << "                Enter a valid phone number: ";
                    cin >> phone_number;
                    length = phone_number.length();
                }
            }

        }

        else
        {
            time_t t = time(NULL);
            tm* timePtr = localtime(&t);

            string password, password_1;
            system("CLS");
            title();
            cout << endl;
            acc_num = rand() % 9999999999 + 10000000000;
            cout << "                                                     Your Account Number is :                                      "    << endl;
            cout << "                                              --------------------------------------                               "    << endl;
            cout << "                                             |               " << acc_num << "             |"                                  << endl;
            cout << "                                              --------------------------------------" << endl << endl;
            cout << "  You are required to set a password for your account: " << endl << endl;
            cout << "  ENTER YOUR PASSWORD : ";
            cin >> password;
            cout << endl;
            cout << "  REENTER YOUR PASSWORD :";
            cin >> password_1;

            while (password_1 != password)
            {
                cout << endl;
                cout << "Your password does not match !!" << endl;
                cout << "Please reenter your password: ";
                cin >> password_1;
            }

            cout << "                                          You are done with your account registration !!" << endl;
            cout << "                                                       NO FEES FOR NEW MEMBERS " << endl;
            cout << "                                       One point will be given for each ringgit in purchase" << endl;
            cout << "                                There are alot of exciting rewards that you can claim using the points" << endl;
            member << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num  <<  '|' << password << '|' << timePtr->tm_mon + 1  << '|' << timePtr->tm_year + 1900 + 1 << '\n' << endl;
            member.close();
        }
    }

        else if (resp == 'B' || resp == 'b')
        {
            time_t t = time(NULL);
            tm* timePtr = localtime(&t);
            fstream member;
            fstream temp;
            member.open("Membership.txt",ios::in);
            temp.open("temp.txt",ios::out);
            int login_attempt = 0, count = 0 , account, extend, pay_amount, acc_renew;
            string pass_input, line, accno_input1, acc_num1, password1, accno_input;
            char dummy, resp, current_year[25], name[25], icno[25], email [40], phone_number[25], acc_num[25], password[25], month[25], year[25], validity[25] ;

            renew_membership:
            system("CLS");
            title();

            cout << "                                                      RENEW MEMBERSHIP                                             "       << endl;
            cout << "                                                     ------------------                                            "       << endl << endl;
            cout << "                                          Enter your account number : ";
            cin >> accno_input;

            ifstream file("Membership.txt");
            while (!file.eof())
            {
                getline(file, line);
                count++;
            }

            int i = 0;

            while(i <= count)
            {
                member.getline(name,25,'|');
                member.getline(icno,25,'|');
                member.getline(email,40,'|');
                member.getline(phone_number,25, '|');
                member.getline(acc_num,25, '|');
                member.getline(password,25,'|' );
                member.getline(month,25,'|' );
                member.getline(validity,25);

                acc_num1 = acc_num;

                if (acc_num1 == accno_input)
                {
                    account = 1;
                    break;
                }

                i = i + 1;
            }
            member.close();

            if ( account != 1 )
            {
                cout << endl;
                cout << "                                  Your account not found !!!"<< endl;
                cout << "                                  Please try again !!" << endl << endl;
                cout << "                                  PLEASE ENTER ANY KEY TO CONTINUE >>> ";
                cin >> dummy;
                goto renew_membership;
            }

            password1 = password;

            cout << endl;
            cout << "                                          Enter your account password : ";
            cin >> pass_input;

            for (login_attempt = 1 ; login_attempt <= 2 ; login_attempt ++)
            {
                if (pass_input == password1)
                {
                    cout << "Login Successful !!!";
                    break;
                }

                cout << endl;
                cout << "Login Failed. Attempt " << login_attempt  << " of 3" << endl;
                cout << "Please re-enter Password: " ;
                cin >> pass_input;

                if (pass_input == password1)
                {
                    cout << "Login Successful !!!";
                    break;
                }

            }

            if ( login_attempt == 3)
            {
                cout << endl;
                cout << "Login Failed. Attempt 3 of 3";

                return 0;
            }

            system("CLS");
            title();

            temp << timePtr->tm_year + 1900;
            temp.close();
            temp.open("temp.txt",ios::in);
            temp.getline(current_year,25);
            temp.close();
            remove("temp.txt");

            renew_membership1:
            cout << " Hello " << name << " ," << endl << endl;
            cout << " Your account is valid until " << month << " - " << validity << endl << endl;
            if ((validity <= current_year) && (((month[0] - 48) < (timePtr->tm_mon + 1))))
            {
                cout << " YOUR ACCOUNT HAS EXPIRED !!!" << endl << endl;
            }
            cout << " Select an option to extend your membership :- " << endl << endl;
            cout << "                      ---------------          ----------------           ---------------" << endl;
            cout << "                     / (a) 1 years  /         /  (b) 3 years  /          / (c) 5 years  /" << endl;
            cout << "                     ---------------          ----------------          ----------------" << endl << endl;
            cout << " Your selection [ a, b, c] = ";
            cin >> resp;
            while((resp != 'A') && (resp != 'a') && (resp != 'B') && (resp != 'b') && (resp != 'C') && (resp != 'c') )
            {
                cout << " Please select a correct option [ a, b, c] : ";
                cin >> resp;
            }

            if ((resp == 'A') || (resp == 'a'))
            {
                extend = 1;
            }
            else if ((resp == 'B') || (resp == 'b'))
            {
                extend = 3;
            }
            else
            {
                extend = 5;
            }

            system("CLS");
            title();

            cout << " You have selected " << extend << " years to extend your membership !!!" << endl;

            int y = 0;
            member.open("Membership.txt",ios::in);
            temp.open("temp.txt",ios::out);

            
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
if (((month[0] - 48) >= (timePtr->tm_mon + 1)) && (validity <= current_year))
            {
                 while(y++, y <= count)
                {
                  member.getline(name,25,'|');
                  member.getline(icno,25,'|');
                  member.getline(email,40,'|');
                  member.getline(phone_number,25, '|');
                  member.getline(acc_num,25, '|');
                  member.getline(password,25,'|' );
                  member.getline(month,25,'|' );
                  member.getline(validity,25);

                  if(y == (i + 1))
                    {
                        int validity1 = validity[3] - 48 + extend ;
                        temp << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << month << '|' << validity[0] <<  validity[1] <<  validity[2] <<  validity1 << '\n';
                    }

                  else
                    {
                        temp << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << month << '|' << validity << '\n';
                    }
                }
            }

            if ((validity <= current_year) && (((month[0] - 48) < (timePtr->tm_mon + 1))))
            {
                 while(y++, y <= count)
                {
                  member.getline(name,25,'|');
                  member.getline(icno,25,'|');
                  member.getline(email,40,'|');
                  member.getline(phone_number,25, '|');
                  member.getline(acc_num,25, '|');
                  member.getline(password,25,'|' );
                  member.getline(month,25,'|' );
                  member.getline(validity,25);

                  if(y == (i + 1))
                    {
                        int current_year1 = current_year[3] - 48 + extend ;
                        temp << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << timePtr->tm_mon + 1 << '|' << current_year[0] <<  current_year[1] <<  current_year[2] <<  current_year1 << '\n';
                    }

                  else
                    {
                        temp << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << month << '|' << validity << '\n';
                    }
                }
            }

            member.close();
            temp.close();

            cout << endl;
            cout << " Do you want to change the years to be extended [Y/N]: ";
            cin >> resp;
            if (resp == 'Y' || resp == 'y')
            {
                goto renew_membership1;
            }

            if (extend == 1)
            {
                pay_amount = 10;
            }

            if (extend == 3)
            {
                pay_amount = 20;
            }

            if (extend == 5)
            {
                pay_amount = 30;
            }

            cout << endl;
            cout << " Your payment upon renewing your membership is RM " << pay_amount << endl;
            cout << " Select the payment method: " << endl;
            cout << "                 (A) CASH  " << endl;
            cout << "                 (B) DEBIT CARD " << endl;
            cout << "                 (C) CREDIT CARD " << endl << endl;
            cout << " Your option [A, B, C] :  ";
            cin >> resp;
            while((resp != 'A') && (resp != 'a') && (resp != 'B') && (resp != 'b') && (resp != 'C') && (resp != 'c') )
            {
                cout << " Please select a correct option [ a, b, c] : ";
                cin >> resp;
            }

            system("ClS");
            title();

            if (resp == 'A' || resp == 'a')
            {
                cout << " You have selected to pay on cash" << endl;
                acc_renew = rand() % 9999999999 + 10000000000;
                cout << "                                              --------------------------------------                               "    << endl;
                cout << "                                             |               " << acc_renew << "             |"                         << endl;
                cout << "                                              --------------------------------------" << endl << endl;
                cout << " This is your ticket number !!! " << endl;
                cout << " Please show this ticket number to the employee " << endl;
                cout << " Thank you !!!" << endl;

            }

            if (resp == 'B' || resp == 'b')
            {
                int debit_card, ccv;
                cout << "You have selected debit card to pay !!" << endl << endl;
                cout << "Enter your debit card number: " ;
                cin >> debit_card;
                cout << endl;
                cout << "Enter your CCV : " ;
                cin >> ccv;
                temp.open("temp.txt",ios::in);
                member.open("Membership.txt",ios::out);
                y = 0;
while(y++, y <= count)
                {
                  temp.getline(name,25,'|');
                  temp.getline(icno,25,'|');
                  temp.getline(email,40,'|');
                  temp.getline(phone_number,25, '|');
                  temp.getline(acc_num,25, '|');
                  temp.getline(password,25,'|' );
                  temp.getline(month,25,'|' );
                  temp.getline(validity,25);
                  member << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << month << '|' << validity << '\n';
                }

                remove ("temp.txt");
                cout << " You are done our beloved customer !!!";
            }

             if (resp == 'C' || resp == 'c')
            {
                int credit_card, ccv;
                cout << "You have selected credit card to pay !!" << endl << endl;
                cout << "Enter your credit card number: " ;
                cin >> credit_card;
                cout << endl;
                cout << "Enter your CCV : " ;
                cin >> ccv;
                temp.open("temp.txt",ios::in);
                member.open("Membership.txt",ios::out);
                y = 0;
                while(y++, y <= count)
                {
                  temp.getline(name,25,'|');
                  temp.getline(icno,25,'|');
                  temp.getline(email,40,'|');
                  temp.getline(phone_number,25, '|');
                  temp.getline(acc_num,25, '|');
                  temp.getline(password,25,'|' );
                  temp.getline(month,25,'|' );
                  temp.getline(validity,25);
                  member << name << '|' << icno << '|' << email << '|' << phone_number <<  '|' << acc_num <<  '|' << password << '|' << month << '|' << validity << '\n';
                }

                remove ("temp.txt");
                cout << " You are done our beloved customer !!!";
            }
        }

        else
        {
            fstream member;
            member.open("Membership.txt",ios::in);
            int login_attempt = 0, count = 0 , account;
            string pass_input, line, accno_input1, acc_num1, password1, accno_input, icno1;
            char resp,dummy, current_year[25], name[25], icno[25], email [40], phone_number[25], acc_num[25], password[25], month[25], year[25], validity[25] ;

            member_info:
            system("CLS");
            title();

            cout << "                                                      MEMBER INFORMATION                                          "       << endl;
            cout << "                                                     --------------------                                            "       << endl << endl;
            cout << "                                          Enter your account number : ";
            cin >> accno_input;
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
ifstream file("Membership.txt");
            while (!file.eof())
            {
                getline(file, line);
                count++;
            }

            int i = 0;
            while(i <= count)
            {
                member.getline(name,25,'|');
                member.getline(icno,25,'|');
                member.getline(email,40,'|');
                member.getline(phone_number,25, '|');
                member.getline(acc_num,25, '|');
                member.getline(password,25,'|' );
                member.getline(month,25,'|' );
                member.getline(validity,25);

                acc_num1 = acc_num;

                if (acc_num1 == accno_input)
                {
                    account = 1;
                    break;
                }

                i = i + 1;
            }
            member.close();

            if ( account != 1 )
            {
                cout << endl;
                cout << "                                  Your account not found !!!"<< endl;
                cout << "                                  Please try again !!" << endl << endl;
                cout << "                                  PLEASE ENTER ANY KEY TO CONTINUE >>> ";
                cin >> dummy;
                goto member_info;
            }

            password1 = password;

            cout << endl;
            cout << "                                          Enter your account password : ";
            cin >> pass_input;

            for (login_attempt = 1 ; login_attempt <= 2 ; login_attempt ++)
            {
                if (pass_input == password1)
                {
                    cout << "Login Successful !!!";
                    break;
                }

                cout << endl;
                cout << "Login Failed. Attempt " << login_attempt  << " of 3" << endl;
                cout << "Please re-enter Password: " ;
                cin >> pass_input;

                if (pass_input == password1)
                {
                    cout << "Login Successful !!!";
                    break;
                }

            }

            if ( login_attempt == 3)
            {
                cout << endl;
                cout << "Login Failed. Attempt 3 of 3";

                return 0;
            }

            system("CLS");
            title();

            icno1 = icno;
            int gender = (icno1.at(11));
            gender = gender % 2;

        cout << endl;
        cout << " ---------------------------------------------------------------------------------------------------------------------------------- " << endl;
        cout << "|                                                                                                                                  |" << endl;
         if (gender == 1)
        {
          cout << "|                   Hello Mr " << name << " ,";

          int y = 25;

          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);

        }

         else
        {
          cout << "|                   Hello Ms " << name << " ,";

          int y = 25;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        }

        cout << "                                                                  |" << endl ;
        cout << "|                                                                                                                                  |" << endl;
        i = 5;
        cout << "|                   Your birthday is " << icno[i-1] << icno[i] << " - " << icno[i-2] << icno[i-3] << " - " << icno[i-5] << icno[i-4] << "                                                                                  |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Identification Number : " << icno;

        int y = 25 ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);

        cout << "                                            |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Email Address : " << email;
        y = 40 ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        cout << "                                                   |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Phone Number : " << phone_number;
        y = 25 ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        cout << "                                                       |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << "|                   Your Account Validity : " << month << " - " << validity;
        y = 25 ;
        do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 50);
        cout << "                                                     |" << endl;
        cout << "|                                                                                                                                  |" << endl;
        cout << " ---------------------------------------------------------------------------------------------------------------------------------- " << endl << endl;
        }
}

 food_drinks()
 {
     system("CLS");
     title();
     fstream foods, drinks;
     char food[25], drink[25], price[25], price_1[25];
     string display1[25];
     string display2[25];
     string display3[25];
     string food1, price_a, drink1, price_b, quantity2;
     int resp1, y, resp, p = 1;
     float quantity, total_price;
     cout <<" Welcome to snacks and drinks section !!! " << endl << endl;

     menu:
     foods.open("Food.txt",ios::in);
     drinks.open("Drink.txt",ios::in);
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                            SNACKS AND DRINKS                                                      | " << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                      SNACKS AVALABLE                   |   PRICE   |                    DRINKS AVAILABLE              |   PRICE   |" << endl;
     cout << "|----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                        |           |                                                  |           |" << endl;
     int i = 0, food1_length, pricea_length, drink1_length, priceb_length;
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
 while (i++, i <= 9 )
     {
         foods.getline(food,25,'|');
         foods.getline(price,25);
         drinks.getline(drink,40,'|');
         drinks.getline(price_1,25);
         food1 = food;
         price_a = price;
         drink1 = drink;
         price_b = price_1;
         food1_length = food1.length();
         pricea_length = price_a.length();
         drink1_length = drink1.length();
         priceb_length = price_b.length();

         cout <<"| (" << i <<")     " << food;
          int y = food1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "                     | RM " <<  price ;

          y = pricea_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 6);

          cout <<"| (" << i <<")     " << drink;

          y = drink1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "               | RM " <<  price_1 ;

          y = priceb_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 6);

          cout <<"|" << endl;
     }
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl << endl;
     cout << " [Food = 1 || Drink = 2 ]" << endl;
     cout << " Do you want to select food or drink = " ;
     cin >> resp;
     cout << " Select the number of food you would like to order: ";
     cin >> resp1;
     cout << " Specify the quantity of selected food to purchase: ";
     cin >> quantity;
     foods.close();
     drinks.close();

     do
     {
     system("CLS");
     foods.open("Food.txt",ios::in);
     drinks.open("Drinks.txt",ios::in);
     title();
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                            YOUR RECEIPT                                                          | " << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl;
     cout << "|                                                   ITEM                                                    | QUANTITY |   PRICE   |" << endl;
     cout << " ----------------------------------------------------------------------------------------------------------------------------------- " << endl ;

      int a = 1;
      while(a <= p)
    {
     i = 0;
     if (resp == 1)
     {
        while (i++, i <= resp1 )
        {
         foods.getline(food,25,'|');
         foods.getline(price,25);
        }

        food1 = food;
        display1[p] = food;
        fstream temp;
        temp.open("temp.txt",ios::out);
        temp << quantity;
        temp.close();
        char quantity1[25];
        temp.open("temp.txt",ios::in);
        temp.getline(quantity1,25);
        temp.close();
        remove("temp.txt");
        quantity2 = quantity1;
        display2[p] = quantity1;
        price_a = price;
        food1_length = food1.length();
        pricea_length = price_a.length();
     }

     else
     {
         while (i++, i <= resp1 )
        {
         drinks.getline(drink,25,'|');
         drinks.getline(price_1,25);
        }

        drink1 = drink;
        display1[p] = food;
        fstream temp;
        temp.open("temp.txt",ios::out);
        temp << quantity;
        temp.close();
        char quantity1[25];
        temp.open("temp.txt",ios::in);
        temp.getline(quantity1,25);
        temp.close();
        remove("temp.txt");
        quantity2 = quantity1;
        display2[p] = quantity1;
        price_b = price_1;
        drink1_length = drink1.length();
        priceb_length = price_b.length();
     }
          float price1 = std::atof(price);
          cout <<"| (" << a <<")     " << display1[p];
          int y = food1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 25);
          cout << "                                                                        | " <<  display2[p] << "   ";
          int quantity_length = quantity2.length();
          total_price = quantity * price1;
          fstream temp;
          temp.open("temp.txt",ios::out);
          temp << total_price;
          temp.close();
          char total_price1[25];
          temp.open("temp.txt",ios::in);
          temp.getline(total_price1,25);
          temp.close();
          remove("temp.txt");
          string total_price2 = total_price1;
          display3[p] = total_price1;

          y = quantity_length;
  do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 5);
          cout << "    | " <<  display3[p] ;
          int totalprice1_length = total_price2.length();

          y = totalprice1_length;
          do
          {
              cout << " ";
              y = y + 1;
          }while( y <= 5);
          cout << "       | \n" ;
          a = a+1;

    }
       foods.close();
       drinks.close();

       cout << endl << endl;
       i = 0;
       goto menu;
       p = p + 1;
    }while(y = 1);

}


int main()
{

    char name [25];
    char time1[25];
    char time2[25];
    char time3[25];
    string customer,phone_number;
    fstream movie;
    movie.open("Movies.txt",ios::in);
    int seat_price, lines;
    char seat_row,seat_column,response,r,r2,pay_res,reuse_response,selection_show,selection_movie1,seat_type,selection_role;
    float remaining = 0,cash = 0;

    menu:
    system("CLS");
    cout << "                  ****************************************************************************************"       << endl;
    cout << "                                             MOVIE TICKET RESERVATION SYSTEM (MTRS)                       "       << endl;
    cout << "                  ****************************************************************************************"       << endl;
    cout << endl << endl ;
cout << "                  ========================        ==========================        ======================    " << endl;
    cout << "                  * (A)  MOVIE BOOKING   *        * (B) TICKET CANCELATION *        * (C) SNACKS & DRINKS *     " << endl;
    cout << "                  ========================        ==========================        ======================     " << endl;
    cout << endl<< endl << endl;
    cout << "                  ========================        ==========================        ======================     "  << endl;
    cout << "                  * (D)    MEMBERSHIP    *        * (E)     EMPLOYEES      *        * (F)   MANAGEMENT   *     " << endl;
    cout << "                  *=======================        ==========================        ======================    " << endl<< endl << endl;
    cout << "                                                            INPUT : ";
    cin >> selection_role;


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
 while(selection_role !='A' && selection_role != 'a' && selection_role !='B' && selection_role != 'b' && selection_role != 'C' && selection_role != 'c' && selection_role != 'D' && selection_role != 'd' && selection_role != 'E' && selection_role != 'e' && selection_role != 'F' && selection_role != 'f')
    {
        cout << endl;
        cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
        cout << "Please select option: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> selection_role;
    }

    movies:
    if ((selection_role == 'A') || (selection_role == 'a'))
    {
        cout << endl;
        cout << "MOVIES AVAILABLE : ";
        showmovielist();

        cout << endl << endl;
        cout << "Please select a movie [1,2,3....]: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> selection_movie1;

        char count = '0';
        string line;

        ifstream file("Movies.txt");
        while (!file.eof())
        {
          getline(file, line);
          count++;
        }

        lines = count - 49;
        count = lines + 48;

        while((selection_movie1 <= '0') || (selection_movie1 > count))
        {
            cout << endl;
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Please select a movie: ";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> selection_movie1;
        }

        selection_movie = (selection_movie1 - 48);

        temp_movie();

        cout << endl;
        cout << "Which show you want to select for [SHOW(1) / SHOW(2) / SHOW(3)]: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> selection_show;

        while((selection_show <= '0') || (selection_show > '3'))
        {
            cout << endl;
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Which show you want to select for [SHOW(1) / SHOW(2) / SHOW(3)]: ";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> selection_show;
        }

        cout << endl;
        cout << "Would you wish to [B]ack, [P]roceed or [R]eselect? :";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> r;

        while (r != 'B' && r != 'b' && r != 'P' && r != 'p' && r != 'R' && r != 'r')
        {
            cout << endl;
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Would you wish to [B]ack, [P]roceed or [R]eselect? :";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> r;
        }

        if ((r != 'b') && (r != 'B'))
            if ((r != 'p') && (r != 'P'))
                        {
                            int i = 0;
                            selection_movie1 = '0';
                            selection_show = i;
                            system("CLS");
                            goto movies;
                        }

            else
            {
                system("CLS");
                goto seats;
            }

        else
        {
            int i = 0;
            selection_show = i;
            system("CLS");
            goto menu;
        }

        cout << endl;

        seats:

        cout << "____________________________________________________________________________________" << endl;
        cout << "                                         SCREEN                                     " << endl;
        cout << "____________________________________________________________________________________" << endl << endl << endl;
        cout << "[A,1]          [A,2]          [A,3]          [A,4]          [A,5]          [A,6]" << endl << endl;
        cout << "[B,1]          [B,2]          [B,3]          [B,4]          [B,5]          [B,6]" << endl << endl;
        cout << "[C,1]          [C,2]          [C,3]          [C,4]          [C,5]          [C,6]" << endl << endl;
        cout << "[D,1]          [D,2]          [D,3]          [D,4]          [D,5]          [D,6]" << endl << endl;
        cout << "[E,1]          [E,2]          [E,3]          [E,4]          [E,5]          [E,6]" << endl << endl;

        cout << endl << endl;
        cout << "Enter the row of seat you would like to book for [ROW : A,B,C...]: ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> seat_row ;

        while(seat_row != 'A' && seat_row != 'a' && seat_row != 'b' && seat_row != 'B' && seat_row != 'c' && seat_row != 'D' && seat_row != 'e' && seat_row != 'E')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Enter the row of seat you would like to book for [ROW : A,B,C...]: ";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> seat_row ;
        }
        cout << endl;
        cout << "Enter the column of seat you would like to book for [COLUMN : 1,2,3...]:  ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> seat_column;

        while(seat_column != '1' && seat_column != '2' && seat_column != '3' && seat_column != '4' && seat_column != '5' && seat_column != '6')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Enter the column of seat you would like to book for [COLUMN : 1,2,3...]:  ";
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> seat_column;
        }
        cout << endl << endl;

        cout << "Your selection of seat is : (" << seat_row << "," << seat_column << ")" << endl;

        cout << "There are two types of seats available:  (A) DELUXE (RM 18) " << endl;
        cout << "                                         (B) NORMAL (RM 13) " << endl << endl;

        cout << endl;
        cout << "Do you want further explanation about the type of seats available in our cinemas before selecting it? (Y/N) :" ;
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> response;
        while (response != 'y' && response != 'Y' && response != 'n' && response != 'N')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Do you want further explanation about the type of seats available in our cinemas before selecting it? (Y/N) :" ;
            cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
            cin >> response;
        }

        if (response == 'y' || response == 'Y')
        {
            cout << endl;
            cout << "- 'DELUXE' seats provides a unique experience to the customers where they will be provided with food during the showtime." << endl;
            cout << "- 'NORMAL' seats does not include the special privileges." << endl;
        }
        cout << endl;
        cout << "Please select the type of seat (A/B): ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> seat_type;
        while (seat_type != 'a' && seat_type != 'A' && seat_type != 'b' && seat_type != 'B')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Please select the type of seat (A/B): ";
            cin >> seat_type;
        }
        cout << endl;
        cout << "--------------------------------------------------" << endl;
        cout << "Enter your name Mr/Ms   : ";
        cin.ignore();
        getline(cin,customer);
        cout << "Enter your phone number : ";
        cin >> phone_number;

        if (seat_type == 'A' || seat_type == 'a')
            seat_price = 18.00;

        else
            seat_price = 13.00;

       
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
        cout << endl;
        cout << "Please select the type of seat (A/B): ";
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> seat_type;
        while (seat_type != 'a' && seat_type != 'A' && seat_type != 'b' && seat_type != 'B')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Please select the type of seat (A/B): ";
            cin >> seat_type;
        }
        cout << endl;
        cout << "--------------------------------------------------" << endl;
        cout << "Enter your name Mr/Ms   : ";
        cin.ignore();
        getline(cin,customer);
        cout << "Enter your phone number : ";
        cin >> phone_number;

        if (seat_type == 'A' || seat_type == 'a')
            seat_price = 18.00;

        else
            seat_price = 13.00;

        cout << "Would you wish to [B]ack, [P]roceed or [R]eselect?" << endl;
        cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n');
        cin >> r2;

        while (r2 != 'b' && r2 != 'B' && r2 != 'p' && r2 != 'P' && r2 != 'r' && r2 != 'R')
        {
            cout << "Sorry! You have entered a wrong selection. Please try again." << endl << endl;
            cout << "Would you wish to [B]ack, [P]roceed or [R]eselect? :";
            cin >> r2;
        }
This is my whole coding. I am really sorry for making you guys to look into my coding but I feel like you can get a understanding if you guys copy the coding into a file and execute it. Thanks in advance
Well. What's this about movies?????

From the first post re snacks & drinks, a simple demo/test code could be (without much input testing etc):

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
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

struct Menu {
	std::string name;
	double price {};
	size_t qty {};
};

using Menus = std::vector<Menu>[2];

constexpr size_t FOOD {0};
constexpr size_t DRINK {1};

void read(std::istream& is, std::vector<Menu>& vm)
{
	for (Menu m; std::getline(is >> std::ws, m.name, '|') >> m.price; vm.push_back(m));
}

void display(const Menus& m)
{
	std::cout << std::setw(134) << std::setfill('-') << '\n';
	std::cout << "|                                                            SNACKS AND DRINKS                                                      | \n";
	std::cout << std::setw(134) << std::setfill('-') << '\n';
	std::cout << "|                      SNACKS AVALABLE                   |   PRICE   |                    DRINKS AVAILABLE              |   PRICE   |\n";
	std::cout << std::setw(134) << std::setfill('-') << '\n';
	std::cout << "|                                                        |           |                                                  |           |\n";

	auto& Food {m[FOOD]};
	auto& Drink {m[DRINK]};

	std::cout << std::setfill(' ') << std::left;

	for (size_t e = 0, lst = std::max(Food.size(), Drink.size()); e < lst; ++e) {
		if (e < Food.size())
			std::cout << "|(" << std::setw(2) << std::right << e + 1 << std::left << ".) " << std::setw(50) << Food[e].name << '|' << std::setw(11) << std::setprecision(2) << std::fixed << Food[e].price;
		else
			std::cout << '|' << std::setw(56) << ' ' << '|' << std::setw(11) << ' ';

		if (e < Drink.size())
			std::cout << "|(" << std::setw(2) << std::right << e + 1 << std::left << ".) " << std::setw(44) << Drink[e].name << '|' << std::setw(11) << std::setprecision(2) << std::fixed << Drink[e].price << "|\n";
		else
			std::cout << '|' << std::setw(50) << ' ' <<  '|' << std::setw(11) << ' ' << "|\n";
	}
}

void add(const Menus& m, std::vector<Menu>& order)
{
	size_t types {};

	do {
		std::cout << "[Food = 1, Drink = 2 ] : ";
		std::cin >> types;
	} while ((types != 1 && types != 2) && (std::cout << "Invalid option\n"));

	--types;

	size_t opt {};

	do {
		std::cout << "Enter menu number: ";
		std::cin >> opt;
	} while ((opt < 1 || opt > m[types].size()) && (std::cout << "Invalid menu number\n"));

	size_t qty {};

	std::cout << "Enter quantity: ";
	std::cin >> qty;

	order.push_back(m[types][opt - 1]);
	order.back().qty = qty;
}

void receipt(const std::vector<Menu>& order)
{
	double total {};

	std::cout << "\nReceipt\n\n";
	std::cout << std::setw(25) << "Name" << std::setw(10) << "Price" << std::setw(10) << "Quantity" << "Total\n";

	for (const auto& [nam, prce, qty] : order) {
		std::cout << std::setw(25) << nam << std::setw(10) << std::fixed << std::setprecision(2) << prce << std::setw(10) << qty << std::setw(10) << prce * qty << '\n';
		total += prce * qty;
	}

	std::cout << "\nTotal is " << total << '\n';
}

int main()
{
	std::ifstream foodfs("food.txt");
	std::ifstream drinkfs("drink.txt");

	if (!foodfs || !drinkfs)
		return (std::cout << "Cannot open input files\n"), 1;

	Menus menus {};

	auto& Food {menus[FOOD]};
	auto& Drink {menus[DRINK]};

	read(foodfs, Food);
	read(drinkfs, Drink);

	display(menus);

	size_t opt {};
	std::vector<Menu> order;

	do {
		std::cout << "\n1. Add food/drink\n";
		std::cout << "0. Display receipt\n";

		std::cout << "\nEnter option: ";
		std::cin >> opt;

		switch (opt) {
			case 1: add(menus, order); break;
			case 0: receipt(order);  break;
			default: std::cout << "Invalid option\n"; break;
		}

	} while (opt);
}

Last edited on
@seeplus Yes my program is about a movie ticket reservation system.
Well fold the contents of main() in my code above into food_drinks() and add the rest of the code......

Last edited on
Hello Mathavan,

After I managed to remove the errors and get the program to compile and run this is what I noticed.

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <limits>
#include <string>  // <--- Had to add. Needed for the string class, std::getline and in the "cin"c and "cout"s/
#include <cctype>  // <--- Added. For "std::tolower() and std::toupper()" + others.
#include <ctime>
#include <cstdlib>

//#include<dos.h>  // <--- May not be available to everyone and not a standard C++ header file.
                   // Does not appear that you are usinf anything from this header file.

using namespace std;  // <--- Best not to use.

int selection_movie;  // <--- Try to avoid global variables like this. Those that begin with const or constexpr are OK.

void title()
{
    constexpr int WIDTH{ 80 };
    const std::string heading{ "MOVIE TICKET RESERVATION SYSTEM (MTRS)" };

    //cout << "                  *************************************************************************************************" << '\n';
    //cout << "                                              MOVIE TICKET RESERVATION SYSTEM (MTRS)                               " << '\n';
    //cout << "                  *************************************************************************************************" << '\n' << '\n';
    std::cout << "\n\n " << std::string(WIDTH, '*') << "\n\n";
    std::cout << std::string((WIDTH / 2) - (heading.size() / 2), ' ') << heading << "\n\n";
    std::cout << ' ' << std::string(WIDTH, '*') << '\n';

    //std::cout << '\n'; // <--- Used for testing. Makes a good break point. Comment or remove when finished.
}

int showmovielist()
{
    char name[25];  // <--- Why a character array and not a std::string?
    char time1[25];
    char time2[25];
    char time3[25];

    system("CLS");

    //fstream movie;

    //movie.open("Movies.txt", ios::in);
    const std::string inFileName{ "Movies.txt" };  // <--- Put File name here.

    std::ifstream movie(inFileName);

    if (!movie)
    {
        std::cout << "\n     File " << std::quoted(inFileName) << " did not open." << '\n';
        //std::cout << "\n File \"" << inFileName << "\" did not open." << std::'\n';

        return 1;
    }

    int count = 0;
    string line;

    //ifstream file("Movies.txt");
    // <--- How do you know it is open? And why are you defining a 2nd variable for the same file?

    while (!movie.eof())  // <--- Does not work the way that you are thinking. Will do 1 extra loop.
    {
        getline(movie, line);
        count++;
    }

    count = count - 1;  // <--- This is needed to compensate for the extra loop. Should not be needed.

    title();

    cout << "======================================================================================================================" << '\n';
    cout << "|SERIAL NUMBER|               TIME[SHOW1]              TIME[SHOW2]              TIME[SHOW3]            |MOVIE NAME|   " << '\n';
    cout << "======================================================================================================================" << '\n';

    int i = 0;

    while (i++, i <= count)
    {
        movie.getline(name, 25, '|');
        movie.getline(time1, 25, '|');
        movie.getline(time2, 25, '|');
        movie.getline(time3, 25);

        cout << "    (" << i << ") " << "\t\t\t " << time1 << "\t\t\t " << time2 << "\t\t\t " << time3 << "\t\t\t " << name << "\n";
    }

    return 0;  // <--- In this case the (0)zero means that everything is OK.
}

Notice the header files I added. I would say that you are at the point where "string" will always be needed for any program that you write.

Your IDE may accept the lines
1
2
3
using namespace std;

string name;

But when you get to a piece of code like cin >> name; or cout << name; The insertion operator does not know how to deal with the string class without the "string" header file.

And "std::getline()" will not work without the "string" header file.

For the function "title" I made some changes. I have no idea what size your display is, but think about who may be running your program. Their screen may not be as wide as yours and what you have output to the screen may wrap when the line gets to the right side. This could make your display unreadable. Try keeping your output more to the left side.

When I run your program I have this:

 ********************************************************************************
                     MOVIE TICKET RESERVATION SYSTEM (MTRS)
 ********************************************************************************

                  ****************************************************************************************
                                             MOVIE TICKET RESERVATION SYSTEM (MTRS)
                  ****************************************************************************************

                  ========================        ==========================        ======================
                  * (A)  MOVIE BOOKING   *        * (B) TICKET CANCELATION *        * (C) SNACKS & DRINKS *
                  ========================        ==========================        ======================

                  ========================        ==========================        ======================
                  * (D)    MEMBERSHIP    *        * (E)     EMPLOYEES      *        * (F)   MANAGEMENT   *
                  *=======================        ==========================        ======================


                                                            INPUT :a

															
     File "Movies.txt" did not open.

The first 3 lines are from the "title" function. The next 3 lines are from what you duplicated in "main" when you should have called the "title" function.

I took out 2 (\n) that replaced the "endl"s you have to tighten up the output. You also need a 7th choice "(G) Quit" I have not progressed far enough to see if the program ever does end.

In the function "showmovielist" note the comments and the code I added.

Lines 62 - 66 can be deleted if you use the next while loop correctly.

Line 78 while (i++, i <= count). I do not believe the "i++" has any effect in the statement because of the comma. Using a comma like this tends to only use whatever is last. Do not strat thinking that you can never use this because there are some places it does work line in for loops.

What you should be doing with line 78 is: while (movie.getline(name, 25, '|')). As soon as the read fails so does the while condition. What I do not understand is why you are using a character array and not a "std::string"?

The message got to big for just 1, so I will finish in the next.

Andy
Pages: 12