can't make a break in this array..


Problem is :

Write a program to assign seats on each flight of airline's only plane(capacity : 10 seats).

If the person type 1, then your program should assign in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then point a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.

Use a single subscript 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 in no longer available.

Your program should of course, never assigned 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 ".



Now my problem is :

I cannot break the program if all the seats are full.



Here is my code :


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
#include<stdio.h>
#include<conio.h>


main()
{
      int max[]={};
      int fc[5]={};
      int ec[5]={};
      int many[5]={0};
      int x,ctr1=0,ctr2=0;
      int num,sum=0,sum2=0;
      int one=1,i;
      char ans;
      
      
      for(i=0;i<10;i++)
      {
      printf("n");
      printf("n");
      printf(" nWelcome to MGM Airlines!  n");
      
      
      
                   printf("n First class section : ");
                   for(x=0;x<5;x++)//for 1st class
                   {
                      printf(" [%d] ", fc[x]);
                   }
                   
                   
                      
                   printf("n Economy section  :    ");
                   for(x=0;x<5;x++)//for economy
                   {
                      printf(" [%d] ", ec[x]);
                   }
                   
                   
      printf(" n ");               
      printf("nplease type 1 for "first class" ");
      printf("nplease type 2 for "economy" : ");
      scanf("%d", &num);
      
                   if(num==1)
                   {
                             
                             sum+=1;
                             printf("n Boarding Pass n First Class Section n Seat #%d ", sum );
                             printf("n");
                             printf("n First class section   :  ");
                             
                             fc[ctr1]=1;
                             for(x=0;x<5;x++)//for 1st class
                              {
                               printf(" [%d] ", fc[x]);
                              }
                              
                              
                             x++; 
                              
                              
                              
                              printf("n Economy class section :  ");
                              for(x=0;x<5;x++)
                              {
                               printf(" [%d] ", ec[x]);
                              }
                              
                              fc[ctr1++];
                              if(ctr1>=5)
                              {
                                        
                                         printf("n");
                                         printf("n");
                                      printf("First Class seats are full, do you want to avail in the economy seats?");
                                      printf("ny---yes || n----no");
                                      scanf("%s",&ans);
                                      if(ans=='y')
                                      {
                                         printf("n Economy class section : ");
                                         ec[ctr2]=1;
                                         for(x=0;x<5;x++)//for 1st class
                                         {
                                          printf(" [%d] ", ec[x]);
                                         }
                                         
                                           fc[ctr2++];
                                          
                                      }// for if(y)
                                      else
                                      {
                                          printf("Next flight leaves in 3 hours");
                                          
                                      }//for else 
                              }//for ctr1>=5
                   }//for first class loop
                      
                      else if (num==2)
                   {
                      sum2+=1;
                      printf("n Boarding Pass n Economy Class Section n Seat #%d ", sum2);
                           printf("n First class section   : ");
                             for(x=0;x<5;x++)//for first class section
                              {
                               printf(" [%d] ", fc[x]);
                              }//for first class section
                              
                             printf("n Economy class section : ");
                             ec[ctr2]=1;
                             for(x=0;x<5;x++)
                              {//for economy section
                               printf(" [%d] ", ec[x]);
                              }
                             fc[ctr2++];
                             
                              if(ctr2>=5)
                              {
                                         printf("n");
                                         printf("n");
                                      printf("Economy seats are full, do you want to avail in the First class seats?");
                                      printf("ny---yes || n----no");
                                      scanf("%s",&ans);
                                      if(ans=='y')
                                      {
                                         printf("n First class section : ");
                                         fc[ctr1]=1;
                                         for(x=0;x<5;x++)
                                         {
                                          printf(" [%d] ", fc[x]);
                                         }//for the for loop
                                           fc[ctr1++];        
                                      }//for if y
                                      
                                      
                                      else if (ans=='n')
                                      {
                                          printf("Next flight leaves in 3 hours");
                                          
                                      }//for else if n
                                      
                         else if(ctr1>=5 && ctr2>=5)
                        {
                        printf("All seats are full ");
                        i=0;
                        }
                        
                              }//for if > 5
                          }   // for else if 2
                          
                    else
                   {
                            
                      printf(" Invalid input ");
                   }       
                   }        
                      getch();
                      
                      }



I hope you all can help me of what is lacking in the code. Thank you!


Topic archived. No new replies allowed.