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!
#include <iostream>
#include <string>
constint 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])
{
returnfalse;
}
}
returntrue;
}
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;
}