Quick Class question

When I try to put in the access code, it doesn't work. The program seems to just refresh the page. I'm sure it is something simple, just hard to find.

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

using namespace std;

enum UserType{Users, Admin};
const unsigned short Max_Titles = 3, Max_Copies = 2, Max_Users = 4, Access_Code = 3;

class BlueBox
{
	int m_revenue;
    string m_inventory[Max_Titles][Max_Copies];
    string m_users[Max_Users][Access_Code];
	

	const unsigned short customer(const unsigned int) ;
    void rent(const unsigned int);
    void returns();
    void sales(const string&);
    void admin() const;
    void error(const string& message)
	{system("Cls"); 
	cout<<message<<endl; 
	exit(0);}

public:
    BlueBox(const string inventory[][Max_Copies], const string users[][Access_Code]);
    void screen();
};

int main()
{
    const string Inventory[][Max_Copies] = {{"Star Wars", "2"},
                                            {"Avengers", "2"},
                                            {"Batman", "2"}};
    const string Users[][Access_Code] = {{"Guest1", "00"},
                                         {"Guest2", "01"},
                                         {"Guest3", "12"},
                                         {"Admin", "99"}};

    BlueBox dvdStore(Inventory, Users);

    dvdStore.screen();

    return 0;
}

BlueBox::BlueBox(const string inventory[][Max_Copies], const string users[][Access_Code]):m_revenue(0)
{
    for(unsigned short titles = 0; titles < Max_Titles; titles++)

        for(unsigned short copies = 0; copies < Max_Copies; copies++)

            m_inventory[titles][copies] = inventory[titles][copies];

    for(unsigned short user = 0; user < Max_Users; user++)

        for(unsigned short codes = 0; codes < Access_Code; codes++)

            m_users[user][codes] = users[user][codes];
}

const unsigned short BlueBox::customer(const unsigned int userType) 
{
    string accessCode;

    if(userType == Users)
        while(true)
        {
            cout << "BlueBox Video Center\n\nCustomer Login:\n Enter Access Code: ";
            cin >> accessCode;

            system("Cls");

            for(unsigned short user = 0; user < Max_Users - 1; user++)
                if(m_users[user][Access_Code - 1] == accessCode)
                    return user;
        }
    else if(userType == Admin)
        while(true)
        {
            cout << "\t\t\tBlueBox Video Center\n\nAdmin Login:\n\nEnter Access Code: ";
            cin >> accessCode;

            system("Cls");

            if(m_users[Max_Users - 1][Access_Code - 1] == accessCode)
            {
                admin();

                break;
            }
        }

    return true;
}

void BlueBox::screen()
{
    char ans;

    do
    {
        cout << "BlueBox Video Center\n\nMain Menu: \n" <<
                "1. Rent\n2. Returns\n3. Admin\n4. EXIT\n \nAnswer: ";
        cin >> ans;

        system("Cls");

        switch(ans)
        {
        case '1':
            {
                rent(customer(Users));
                break;
            }
        case '2':
            {
                returns();
                break;
            }
        case '3':
                customer(Admin);
        }
    }while(ans != '4');
}
void BlueBox::rent(const unsigned int user)
{
    unsigned short titleCounter = 0;
    char ans;

    while(true)
    {
        cout << "\t\t\tBlueBox Video Center\nWelcome " <<
                m_users[user][0]<<endl<<endl<<"Which title to Rent:"<<endl<<endl;

        for(unsigned short titles = 0; titles < Max_Titles; titles++)

            if(m_inventory[titles][Max_Copies - 1].at(0) > '0')
                cout << ++titleCounter << ". "<<setw(12)<< m_inventory[titles][0]<<" | "<<
                     m_inventory[titles][Max_Copies - 1]<<" copies left"<<endl;

        if(titleCounter == 0)

            cout<<"No DVDS To Rent - Out Of Order! Sorry for the inconvenience"<<endl;
			cout<<"Exit to return to main screen"<<endl<<endl;

        cout << ++titleCounter << ". Exit\n\nAnswer: ";
        cin >> ans;

        system("Cls");
		
        if(ans - 48 == titleCounter)
            break;
        else if(ans - 48 > titleCounter || ans - 48 < 1)
        {
            titleCounter = 0;

            continue;
        }
        else
        {
            unsigned short titlePickerCounter = 0;

            for(unsigned short titles = 0; titles < Max_Titles; titles++)
            {
                if(m_inventory[titles][Max_Copies - 1].at(0) > '0')
                    titlePickerCounter++;

                if(ans - 48 == titlePickerCounter)
                {
                    m_inventory[titles][Max_Copies - 1].at(0)--;

                    break;
                }
            }
        }

        titleCounter = 0; 
    }
}

void BlueBox::returns()
{
    unsigned short titleCounter = 0;
    char ans;

    while(true)
    {
        cout << "\t\t\tBlueBox Video Center\n\nWhich Title to Return:\n---\n";

        for(unsigned short titles = 0; titles < Max_Titles; titles++)
            if(m_inventory[titles][Max_Copies - 1].at(0) < '2')
                cout << ++titleCounter << ". " << setw(12) << m_inventory[titles][0] << " | "
                    << 2 - atoi(m_inventory[titles][Max_Copies - 1].c_str()) << " copies missing\n";

        if(titleCounter == 0)
        {
            system("Cls");

            return;
        }

        cout << ++titleCounter << ". Exit\n---\nAnswer: ";
        cin >> ans;

        system("Cls");
		
        if(ans - 48 == titleCounter)
            break;
        else if(ans - 48 > titleCounter || ans - 48 < 1)
        {
            titleCounter = 0;

            continue;
        }
        else
        {
            unsigned short titlePickerCounter = 0;

            for(unsigned short titles = 0; titles < Max_Titles; titles++)
            {
                if(m_inventory[titles][Max_Copies - 1].at(0) < '2')
                    titlePickerCounter++;

                if(ans - 48 == titlePickerCounter)
                {
                    m_inventory[titles][Max_Copies - 1].at(0)++;

                    sales(m_inventory[titles][0]);

                    break;
                }
            }
        }

        titleCounter = 0; 
    }
}

void BlueBox::sales(const string& titleName)
{
    cout << "Thank you for returning " << titleName << " within 24 hours!\n\n";
    cout << "The cost is $1.00 - Thank you for your business!\n\n";

    system("Pause");
    system("Cls");

    m_revenue++;
}
void BlueBox::admin() const
{
    cout << "\t\t\tBlueBox Video Center\n\nAdmin Panel:\n\n\nCurrent DVDs IN STOCK:\n\n";

    for(unsigned short titles = 0; titles < Max_Titles; titles++)
        if(m_inventory[titles][Max_Copies - 1].at(0) > '0')
            cout << setw(12) << m_inventory[titles][0] << " | " <<
                     m_inventory[titles][Max_Copies - 1] << " copies\n";

    cout << "Total Revenue:\n\n$" << m_revenue << ".00\n\n";

    system("Pause");
    system("Cls");
}
Topic archived. No new replies allowed.