Booleans for Restaurant Reservation System

Hi guys

I'm not very familiar with booleans and arrays, so when I have to use the two of them together... you get the idea. This program is a restaurant reservation system for a restaurant with 20 tables. This is my requirement:

"User needs to input the table number (Tables are numbered from 0 to 19). If the table is not available (reserved), inform the user that the selected table is not available. If the table is available, then ask for the name (name is a single word, no space) and mark the table as reserved. Each feature should be located inside its own function. I would recommend keeping two arrays (parallel arrays!), both are size 20, one of type boolean (true/false -- reserved/available) and the other one of type string (name on reservation if reserved, blank otherwise). "

In my function to reserve a table, I'm not sure how to return "not available" to the user when the table is not available. Maybe I am declaring my booleans wrong? Please let me know how I can do this. Thank you very much guys!

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

using namespace std;

// Prototypes
void AddReservation(string names[], bool tables [])

int main()
{
	// Declaration of arrays
	bool tables[20];
	string names[20];

	int choice = 1;
	while ( choice != 0)
	{
		// User will select a choice
		cout << "Welcome to RestaurantReserve System!" << endl;
		cout << "1 - Reserve a Table" << endl;
		cout << "2 - Clear a Reservation" << endl;
		cout << "3 - Report" << endl;
		cout << "0 - Exit" << endl;

		// User input
		cin >> choice;

		// Reserve a table
		if (choice == 1)
		{
			AddReservation(names,tables); // Calling function
		}

	}


	system("PAUSE");
	return 0;
}

void AddReservation(string names[], bool tables [])
{
	// Get data from user
	string n;
	cout << "What is the name of the reserver?" << endl;
	cin >> n;

	bool t;
	cout << "What table would they like to reserve?" << endl;
	cin >> t;

	// Put inside array
	names[] = n;
	tables[] = t;

}
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
#include <iostream>
#include <string>

const int numTables = 5; //it's always good to have a variable to plug into things instead of manually typing it over and over

bool IsTableAvailable(bool tablesReserved[], int tableNumber)
{
	for(int i = 0; i < numTables; i++)
	{
		if(i == tableNumber && tablesReserved[i])
		{
			return false;
		}
	}

	return true;
}

int main()
{
	std::string tables[numTables] = { "T0", "T1", "T2", "T3", "T4"};
	bool tablesReserved[numTables] = { true, false, false, true, true };

	int input;

	std::cout << "Pick a table: \n";
	std::cin >> input;

	if(IsTableAvailable(tablesReserved, input))
	{
		std::string name;

		std::cout << "Table is available. May I take your name please?\n";
		std::cin >> name;

		tables[input] = name;
	}
	else
	{
		std::cout << "Table is unavailable.\n";
	}

	return 0;
}
Topic archived. No new replies allowed.