How can i improve this program

Hi All. So this is a program that i have written. I am rather new to c++ and for homework we were asked to write this program. This has taken me hours and is miles away from perfection. Could you give me hints to how i can improve it. 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
248
249
250
251
252
253
254
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
//Global Variables
char seatPlan[10][6];
	char varStore =65;
	char character= 'X';
	int convert, row, row2, choice;
	char firstName[15], surname[15];
	char col, ans;
	//Functions
	void banner();
	int numcheck(int lownum, int highnum);
	int bookSeat();
	void seatingPlan();
	char validate();
	void delegates();

int main()
{
	char ans;
	//======================Menu===================================
	
	do{
	banner();

	cout<<"Welcome to the conference booking system:\n\n";
				cout<<"Option 1: Book A Seat\n";
				cout<<"Option 2: View Seating Plan\n";
				cout<<"Option 3: Exit\n\n";
				cout<<"Please choose an option: "; 
				cin>>choice;
	switch(choice)
		{//Switch Open
				
			case 1://book seat
				system ("cls");
				seatingPlan();
				bookSeat();
				break;
			case 2://View seat plan
				system ("cls");
				seatingPlan();
				seatPlan[row-1][convert-65];
				
				cout<<"Would you like to view the delegates, that have booked? (Y/N): ";
				cin>>ans;
				validate();
				if (ans=='Y' || ans=='y')
				{
				 delegates();
				}
				else
					cout<<" ";
				break;
			case 3: //exit
					cout<<"";
					return 0;
					break;
				default: cout<<"Thank you for using This Booking System\n";
					break;

					}//switch closed
					cout<<"Do you want to return to main menu (Y/N):  ";
					cin>>ans;
					validate();
					system ("cls");
			
	}while (ans=='Y' || ans=='y');// Loops back to the main menu
	return 0;
	
	banner();
	cout<<endl;
}
void banner()///Banner For Program
{
	cout<<"=============================================\n";
	cout<<"=*******************************************=\n";
	cout<<"=***********CONFERENCE ROOM*****************=\n";
	cout<<"=*******************************************=\n";
	cout<<"=============================================\n";
}
void seatingPlan()

{
	banner();
	
		for(row=0; row<10; row++)
		{
			varStore=65;
			for(int col=0; col<6; col++)
			{
				seatPlan[row][col] = varStore++;
			}
		}
		seatPlan[4][3]='X';//Prints X in D5
		seatPlan[5][4]='X';//Prints X in E6
		seatPlan[row2-1][convert-65] = 'X';//Prints X, into grid. (needed when looping around program)
		for ( row=0; row<10; row++)
		{
			cout<<"\n"<<row+1<<"\t";
			for (int col= 0; col<6; col++)
			{
				cout<<seatPlan[row][col]<<"\t";//prints grid
			}
		}
		seatPlan[row-1][convert-65] = 'X'; //Prints X Based on the user choice
		cout<<"\n\n";
}
int bookSeat()
{  
	bool seatBooked =false;
	do
	{
		do
			{
				do
					{	
						////Draw grid based on user choice	
						cout<<"Please Select a seat from the above seating plan:\n";
						cout<< "Please Enter A Row Number = ";
						cin >> row;
						int row = numcheck( 1, 11 ) ;// checks numbers from 1-10
						row2=row;
						if (row2==99)
						{
							system("cls");
							cout<<"Seating Plan: \n";
							seatingPlan();
							delegates();
						}
						if(row<1 || row>10)
						{
							cout<<"Please enter a valid row number: ";
							cin>>row;
						}
						cout<<"Please Enter A Column Letter: ";
						cin >> col; 
						convert = col; //converts user char to ASCII Value
						if (isupper(col))
						{
							//null
						}
						else
						{
							while(!isupper(col))//Checks upcase char, if not user will repeat process
								{
									cout <<"please enter a valid, uppercase letter: ";
									cin >> col;
								}
						}
						if((col=='D' && row2==5) || (col=='E' && row2==6))
							{
								cout<<"This Seat has been booked, Please try again!!\n";
							}
							else
							{
								seatBooked=true;
								convert=col;
							}
						
					}while(!seatBooked);
				system ("cls");
				banner();	
				seatPlan[row-1][convert-65] = 'X'; //Prints X Based on the user choice
				for (row=0; row<10; row++)
				{
					cout<<"\n"<<row+1<<"\t";
					for (int col= 0; col<6; col++)
						{
							cout<<seatPlan[row][col]<<"\t";
						}
					seatPlan[4][3]='X';//Prints X in D5
					seatPlan[5][4]='X';//Prints X in E6
				}
		
	cout<<"\n\n";
	cout<<"Thank you, Your Allocated seat has been Marked with an X.\n";
	cout<<"To confirm your seat Please enter your details below\n";
	cout<<"Please Enter Your First Name: " ;
	cin>>firstName;
	cout<<"Please Enter Your Second Name: " ;
	cin>>surname;
	cout<<"\n";
	cout<<"Confirm Your booking\n";
	cout<<"--------------------\n";
	cout<<"Your name is: "<<firstName<< " " <<surname<< "\n";
	cout<<"You have pre booked seat " <<col<< ""<<row2;
	cout<<" is this correct (Y/N): " ;
	cin>>ans;

	if(ans=='y' || ans=='Y')
	{
	cout<<"Thank you " <<firstName<<" "<<surname<<endl; 
	cout<<"Your Seat " <<col<< "" <<row2<< " Has been booked";
	cout<<"\n";
	}
	else
	{
		system("cls");
		seatingPlan();
	}

	}while(ans=='n' || ans=='N');
	cout<<"would you like to book another seat? (Y/N): ";
	cin>>ans;
	}while(ans=='Y' || ans=='y');
	

	return 0;
}
char validate()
{
	bool charvalid=false;
	do
	{
		if(ans!='Y'&& ans!='y')
		{
			cout<<"This is not a valid answer! \n";
			cout<<"Please try again using (Y/N) Only: ";
			cin>>ans;
		}
		else;
		{
			charvalid=true;
		}
	}while(charvalid);
	return charvalid;
}
int numcheck( int lownum, int highnum )
{
    if( std::cin >> row ) // if the user has entered a number
    {
        if( row < lownum ) std::cerr << "Error: the number is too small\n" ;
        else if( row >= highnum ) std::cerr << "Error: the number is too big\n" ;
        else return row ;
    }
    else
    {
        std::cerr << "This not a number, Please Try Agian: \n" ;
        std::cin.clear() ; // clear the error state
        std::cin.ignore( 1024, '\n' ) ; // and discard entry
    }

    return numcheck( lownum, highnum ) ; // try again
}
void delegates()
{
	char bookedName[4][8] = { "Harry", "Potter", "Frodo", "Baggins" };
	cout<<bookedName[0]<< " "<<bookedName[1]<< " D5" <<endl;
	cout<<bookedName[2]<< " "<<bookedName[3]<<" E6"<<endl;
	cout<<firstName<< " " <<surname<< " "<<col<< ""<<row2<<"\n";
}
no thats fine, i agree it would take ages. i have a few issues i cant seem to fix.

When the program loads you come to a menu. If you select option 1. You are taken to a screen to book a seat for a conference room. when you get to this screen you are asked to enter a row. If you enter an int between 1-9 the program hangs and does nothing else, but if you was to press a char instead of a number, you can an error message, and you are re prompted for a number. if you then enter an Int, it will proceed through the rest of the program .

so basically you have to make a mistake before you get any where
no idea if it is related to the numcheck(), that checks the user to input to ensure that it is an int and not a char
Topic archived. No new replies allowed.