Airplane Reservation

Help! I can't see what's wrong in my program I just put a part of my program in a function then the output is wrong but when I didn't put a part of my program in function the output is correct here's my program:

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
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <windows.h>
#define p printf
#define s scanf

void checks();
	char seat[5][4][2] = {{{'1','A'},{'1','B'},{'1','C'},{'1','D'}},
			{{'2','A'},{'2','B'},{'2','C'},{'2','D'}},
			{{'3','A'},{'3','B'},{'3','C'},{'3','D'}},
			{{'4','A'},{'4','B'},{'4','C'},{'4','D'}},
			 {{'5','A'},{'5','B'},{'5','C'},{'5','D'}}};
	char choice, ch, seatnum[2];
	int x, y, z, check;
	

main(){
	do{
		system("cls");
		p("Enter your choice from the options below:\n");
		p("[1] Display the Seat Arrangement\t[3] Exit the Program\n[2] Input the Passenger's Choice\n");
		s("%d", &choice);
		
		switch(choice){
			case 1: {
				p("\n      Seat Assignment\n\n");
				for(x = 0; x < 5; x ++){
					for(y = 0; y < 4; y ++){
						for(z = 0; z < 2; z ++){
							p("%c", seat[x][y][z]);
						}
						p("\t");
					}
					p("\n\n");
				}
				p("Proceed with the reservation/assigning [Y/N]? "); s(" %c", &ch);
				if (toupper(ch) == 'Y'){
					p("Enter seat number you want: "); s("%s", &seatnum);
					checks();
				}
				ch = 'N';
				break;
			}
			
			case 2: {
				p("Enter seat number you want: "); s("%s", &seatnum);
				checks();			
				ch = 'N';
				break;
			}
			
			case 3:{
				exit(0);
			}
		}
	} while (toupper(ch) == 'N');
}

void checks()
{
	for(x = 0; x < 5; x ++){
					for(y = 0; y < 4; y ++){
						if (seat[x][y][0] != 'X' && seat[x][y][1] != 'X'){
							if (seatnum[0] == seat[x][y][0] && seatnum[1] == seat[x][y][1]){									
							        seat[x][y][0] = 'X';
									seat[x][y][1] = 'X';
									check = 1;
							}
						}
					}
				}
				if (check != 1){
					p("Sorry the seat number %s is already occupied!", seatnum);
					getch();
				}
}
Last edited on
Topic archived. No new replies allowed.