Hello C program Gurus...
i have problem with my programming. i can run my prog but its something not right...
my prog is to make an automated reservation system program to assign seats on flight of the plane that have apacity 10 seats.
the program should display the following menu of alternatives:
Please type 1 for “first class”
Please type 2 for “economy”
If the person types 1, then thr program should assign a seat in the first class section (seats 1 – 5). If the person types 2, then the program should assign a seat in the economy section (set 6 – 10). the program should then print a boarding pass indicating the person’s seat number and whether it is in the first class or the economy section of the plane.
Use a single subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.
The program should never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no then print the message “Next flight leaves in 3 hours”.
below is my prog and i realy hope that u can help me make my prog run well....
thanks so much...
#include <stdio.h>
#define SENTINEL -1
int
main(void)
{
int ary[] = {0,0,0,0,0,0,0,0,0,0};
int group = 0,
seat_no = 0;
int i,
chek;
while (group != SENTINEL) {
printf("INSTRUCTION..\n");
printf("Please type 1 for FIRST CLASS\n");
printf("Please type 2 for ECONOMY CLASS\n");
scanf("%d", &group);
printf("Your Class is: %d", group);
i=0;
while (group == 1 && i < 5) {
if (ary[i] == 0) {
ary[i] = 1;
seat_no = i + 1;
i = 5;
}
else if (ary[4] == 1) {
printf("FIRST CLASS is already full\n");
printf("Type 0 if you want to change to ECONOMY CLASS\n");
printf("Type 1 if no");
scanf("%d", &chek);
if (chek == 0) {
group = 2;
}
else {
printf("NEXT FLIGHT WILL LEAVE IN THREE HOURS\n");
}
}
else {
i += 1;
}
}
i=5;
while (group == 2 && i < 10) {
if (ary[i] == 0) {
ary[i] = 1;
seat_no = i + 1;
i = 10;
}
else if (ary[9] == 1) {
printf("ECONOMY CLASS is already full\n");
printf("Type 0 if you want to change to FIRST CLASS\n");
printf("Type 1 if no");
scanf("%d", &chek);
if (chek == 0) {
group = 1;
}
else {
printf("NEXT FLIGHT WILL LEAVE IN THREE HOURS\n");
}
}
else {
i += 1;
}
}
switch (seat_no) {
case 1:
case 2:
case 3:
case 4:
case 5:
printf("BOARDING PASS\n");
printf("Class: FIRST CLASS\n");
printf("Seat : %d\n", seat_no);
printf("Thank You\n");
case 6:
case 7:
case 8:
case 9:
case 10:
printf("BOARDING PASS\n");
printf("Class: ECONOMY CLASS\n");
printf("Seat : %d\n", seat_no);
printf("Thank You\n");
default:
printf("\n");
}
}
return (0);
}
from: syuk