Hi guys,
Could someone point me in the right direction, please? I'm trying to expand my system to accommodate the reservation of consecutive seat numbers.
The user is prompted for a row number, seat number and then the amount of consecutive seats he would like to book.
For example: The user enters row: 1, seat number: 1 and then 2 to book seats 1 and 2 in row 1. I can reserve a single specified seat, but I'm a little stuck on the consecutive bookings
#include "stdafx.h"
#include <iostream>
using namespace std;
char answer;//made global so promptUser function can access answer
//function to output a visual diagram of the seating plan
//outputs the array with 10 rows and 4 columns
void printDiagram (char seats [][5])
{
cout<<"\tSEATS"<<endl;//header
cout<<"\t1 2 3 4"<<endl;//to output header of numbers to table
//looping through the array's rows
for (int i = 1; i <11; i++)//for loop to output table, starting from row 1
{ cout<<"Row "<<i<<"\t";
//looping through the columns of the row
for (int j = 1; j<5; j++)
cout<<seats[i][j]<<" ";//to ouput the U's and !'s for the rows
cout<<endl;
}
}
void bookConsec (char seats[][5])
{
int row, number, require; //row no, seat no and number of consecutive seats required.
cout<<"Please enter row (1-10),\nthen a seat number (1-4) \nand number of seats required: \n";
cin>>row;
while (row<1 || row>10)//while loop to test if row is between 1 and 10
{
cout<<"This row doesnt exist, please enter a new row: \t";
cin>>row;
}
cout<<"\n";//used to line up the input for the seat nr
//cout<< setw(48);
cin>>number;
while (number < 1 || number > 4)//while loop to test if seat number is between 1 and 4
{
cout<<"This seat doesnt exist, please enter a new seat number: \t";
cin>>number;
}
cout<<"\n";
cin>>require;
while (number < 1 || number > 40)//while loop to test if seat number is between 1 and 40
{
cout<<"Maximum number of seats allowed for this booking: 40\t";
cin>>require;
}
if ( seats[row][number] == 'U' )//this checks if seat is available, if it is, sets the seat to reserved
{
cout<<"Your reservation details: "<<endl<<endl;
seats[row][number] = '!';//reserved
}
else cout<<"Seat already booked. Please select another seat."<<endl<<endl;
}
int main()
{
char seats [11][5]; //declare array seats, 10 rows accross, 4 rows down
char menu; //variable used to ask if user wants to see the menu again
int choice; //variable for menu answer
for (int i = 1; i <11; i++)//initialize all seats to 'U'
{
for (int j = 1; j<5; j++)
seats[i][j] = 'U';
}
do //use a do while loop here so user can view many more than one time if necessary
{
//Print menu
cout<<"\n\t\t\tMenu"<<endl;
cout<<" ---------------------------------------------"<<endl;
cout<<"\t1) Reserve consecutive seats"<<endl;
cin>>choice;
switch (choice)//switch statement to process user input from the menu above
{
case 1:
{
bookConsec (seats);//call promptUser function
printDiagram (seats);//call printDiagram function (prints diagram to screen)
break;
}
case 7: //function 'main' will end if user enters 7 (return 0)
return 0;
break;
default: return 0; //Any other numbers entered by the user will end the function
}
cout<<endl<<"Do you wish to see the menu again?: (y/n) ";//allows user to view the menu again
cin>>menu;
cout<<endl<<endl;
}
while (toupper(answer)=='Y');
return 0;
}
.