Cannot update the status

This is a hotel reservation program. The problem is that the status doesn't update to rented even if I pay for the room. Help please. Thanks :)

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
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <conio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <Windows.h>

using namespace std;

void Border(int border);
void Title(int border);
void Main_Menu(string Name,string choice,string choiceOfRoom,string status[4], int border,int payment,int days,int balance,int change);
void Enter_Name(string &Name);
void Avail_Rooms(int border);
void Reserve_Room(string choiceOfRoom, string Name, string choice, int border, int payment, int days, int balance, int change, string status[4]);
void Reservation_Payment(int payment, int days, int balance, int change, string choiceOfRoom, string status[4]);

int main()
{
	string Name, choice, choiceOfRoom, status[4];
	int border = 0, payment = 0, days = 0, balance = 0, change = 0;
	system("color 4F");

	Main_Menu(Name, choice, choiceOfRoom, status, border, payment, days, balance, change);

	return 0;
}

void Border(int border)
{
	for (border = 0; border < 80; border ++)
	{
		Sleep(20);
		cout << "\3";
	}
}
void Title(int border)
{
    Border(border);
	Sleep(100);
    cout << "\n\t\t\t\tHotel California\n\n";
	Sleep(100);
    Border(border);
    cout << endl << endl;
}
void Main_Menu(string Name,string choice,string choiceOfRoom,string status[4], int border,int payment,int days,int balance,int change)
{


    cout << "******************************** Hotel de Laylo ********************************";
    cout << "\n 1. Reserve A Room";
    cout << "\n 2. Cancel Reservation";
	cout << "\n 3. View Rooms";
    cout << "\n 4. Exit";
    cout << endl << endl;
    cout << "\n********************************************************************************";
	
	do
	{
		cout << "\n\nEnter your choice: "; cin >> choice;

			if (choice == "1")
			{
				system("cls");
				Reserve_Room(choiceOfRoom, Name, choice, border, payment, days, balance, change, status);
				break;
			}
			else if (choice == "2")
			{
				cout << "Icancel mo";
				system("cls");
				break;
			}
			else if (choice == "3")
			{
				system("cls");
				Title(border);
				Avail_Rooms(border);
				system("pause");
				system("cls");
				Main_Menu( Name, choice, choiceOfRoom, status,  border, payment, days, balance, change);
			}
			else if (choice < "1" || choice > "4")
				cout << "\n\nInvalid choice!\n";
	}while(choice != "4");
}
void Enter_Name(string &Name)
{
	bool running = true;

    string Temp, address, number;
    Name = "";
    cout << endl << "Name: ";
    cin.ignore();
    getline(cin, Temp);

	cout << "Address: ";
	getline(cin, address);


	do
	{
	cout << "Contact Number: "; cin >> number;

	if (number.length() > 11 || (number < "0" || number > "9"))
		cout << "\nInvalid number!\n\n";
	else if (number < "0" || number > "9")
		cout << "\nInvalid number!\n\n";
	else
		running = false;
	}while(running);

	
}
void Avail_Rooms(int border)
{
	border = 0;

	string Room[4] = { "Standard", "Superior", "Deluxe", "Suite" };
	string status[4] = { "Available", "Available", "Available", "Available", };
	 int amount[4] = { 3000, 3200, 4000, 5000 };

	cout << setw(20) << "AVAILABLE ROOMS" << "\t\tAMOUNT" << "\t\t\tSTATUS";
    cout << endl << endl;
    cout << setw(10) << "a. " << Room[0] << "\t\tPhp " << amount[0] << "\t\t" << status[0] << endl;
    cout << setw(10) << "b. " << Room[1] << "\t\tPhp " << amount[1] << "\t\t" << status[1] << endl;
    cout << setw(10) << "c. " << Room[2] << "\t\tPhp " << amount[2] << "\t\t" << status[2] << endl;
    cout << setw(10) << "d. " << Room[3] << "\t\t\tPhp " << amount[3] << "\t\t" << status[3] << endl;
    cout << endl;

	cout << endl;
}

void Reserve_Room(string choiceOfRoom, string Name, string choice, int border, int payment, int days, int balance, int change, string status[4])
{

	border = 0;

	Title(border);
	cout << endl;
	cout << "The Days Hotel Batangas is situated at Pastor Village, Pallocan West, "<< endl << "Batangas City. " << " It offers free internet wifi, parking lot and you can find Laylothere. " << endl << endl;

	for (int x = 0; x < 80; x++)// para sa guhit
	{
		cout << "_";
	}
	
	cout << endl;

	Avail_Rooms(border); // list of rooms

	for (int x = 0; x < 80; x++) // para sa guhit
	{
		cout << "_";
	}

	cout << endl << endl;


		do
		{
			cout << "Press x to Exit" << endl ;
			cout << "Please enter your choice: "; cin >> choiceOfRoom;

			if (choiceOfRoom == "a")
			{
				Enter_Name(Name);
				Reservation_Payment(payment, days, balance, change, choiceOfRoom, status);
				_getch();
				system("cls");
				Main_Menu( Name, choice, choiceOfRoom, status,  border, payment, days, balance, change);
				break;
			}
			else if (choiceOfRoom == "b")
			{
				Enter_Name(Name);
				Reservation_Payment(payment, days, balance, change, choiceOfRoom, status);
				_getch();
				system("cls");
				Main_Menu( Name, choice, choiceOfRoom, status,  border, payment, days, balance, change);
				break;
			}
			else if (choiceOfRoom == "c")
			{
				Enter_Name(Name);
				Reservation_Payment(payment, days, balance, change, choiceOfRoom, status);
				_getch();
				system("cls");
				Main_Menu( Name, choice, choiceOfRoom, status,  border, payment, days, balance, change);
				break;
			}
			else if (choiceOfRoom == "d")
			{
				Enter_Name(Name);
				Reservation_Payment(payment, days, balance, change, choiceOfRoom, status);
				_getch();
				system("cls");
				Main_Menu( Name, choice, choiceOfRoom, status,  border, payment, days, balance, change);
				break;
			}
			else
				cout << "\nInvalid Choice!\n\n";
		}while (choiceOfRoom != "x");


}

void Reservation_Payment(int payment, int days, int balance, int change, string choiceOfRoom, string status[4])
{
	cout << endl;
	cout << "Enter the number of days: "; cin >> days;
	
	if (choiceOfRoom == "a")
	{
		balance = days  * 3000;
		status[0] = "Reserved";
		
	}
	else if (choiceOfRoom == "b")
	{
		balance = days  * 3200;
		status[1] = "Reserved";
	}
	else if (choiceOfRoom == "c")
	{
		balance = days  * 4000;
		status[2] = "Reserved";
	}
	else if (choiceOfRoom == "d")
	{
		balance = days  * 5000;
		status[3] = "Reserved";
	}

	cout << "\nYour balance is Php " << balance << endl;
	cout << "Enter your full payment: "; cin >> payment;

	change = payment - balance ;

		if (change > 0)
			cout << "\nYour change is Php " << change << ".";

	cout << "\nEnjoy your stay and make yourself at home! Thank you!";
	cout << endl;
}
Last edited on
It looks like you need to review or read up on variable scope: http://www.dev-hq.net/c++/17--variable-scope-and-this

Also you need to review how and when to pass variables to and from functions using reference parameters.

Look at the beginning of your Avail_Rooms() function:
1
2
3
4
5
6
void Avail_Rooms(int border)
{
	border = 0;

	string Room[4] = { "Standard", "Superior", "Deluxe", "Suite" };
	string status[4] = { "Available", "Available", "Available", "Available", };

First you pass a value into this function by value, border, but then you immediately set it to zero. So there is actually no reason for sending this variables into the function. Remember because border is passed by value any changes made to this variable in this function are lost when the function returns.

Next you always start with all rooms "Available", perhaps you should consider passing this variable to and from the functions that require to know what rooms are available, so it can be altered if desired.

Thanks for replying. So I cannot use void this time?

Edit: I use int and it works like a charm. Haha :)
Last edited on
Okay how did changing the return type "fix" the problem. And why are you passing border into so many functions that never use the value?

closed account (SECMoG1T)
Okay how did changing the return type "fix" the problem.

That what i was wondering too..., my suggestions were that he/she should initialize those arrays in main, then get rid of those local arrays
1
2
string Room[4] = { "Standard", "Superior", "Deluxe", "Suite" };
	string status[4] = { "Available", "Available", "Available", "Available", };

because they only exist in the scope of that function alone ... they are always created whenever that function is called and destroyed on exit.

Best advice would be to construct a class that would control all those action rather than having everything laying allover sometimes that can get confusing :D.
Last edited on
Topic archived. No new replies allowed.