Alright so im supposed to represent an airline. total # of seats is 10. Passangers can choose whether to sit in first or economy. This is what i have so far. If you try the program and try to go from first to economy you will see that it skips seats. For ex. #1 in First, then #7 in Economy then #3 in First. It also wont say that economy is full or that the airplane is full. Any tips?

#include<stdio.h>
#include<stdlib.h>

int main (void)

{
int seat;
int s[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int f = 0; // first class//
int e = 5; // economy class//
int i;


printf("Welcome to the Airline Reservation system \n");

    for(i=0;i<=10;i++)
    {

        printf("Enter 1 for First class, 2 for Economy Class or 0 to Exit \n");
        scanf("%d", &seat);
        {
        if(seat==1 && s[f]<=5)

            printf("You are in seat #%d in the First Class \n", s[f]);
            f++;

            if(s[f]>6)
            {
            printf("First class is full \n");
            printf("Please enter 2 to switch to Economy Class or 0 to exit \n");
            }
        }

        {
        if(seat==2 && s[e]>5)

            printf("You are in seat #%d in the Economy Class \n", s[e]);
            e++;

            if(s[e]>10)
            {
            printf("The economy class is full \n");
            printf("Please enter 1 to switch to First Class or 0 to exit \n");
            }
        }

        {
        if(seat==s[f]>5 && seat==s[e]>10)
            printf("The airplane is full. Next flight leaves in 3 hours \n");
        }

        {
        if(seat==0)
            break;
        }

    }


system("PAUSE");

}

you can see why it doesn't work if you print out the values of the variables before the conditions then you can make the right adjustments

if you print the value of the variables before some of the condition statements you can find where the problem oocurs and check if the condition set or use of loop is wrong and make necessary changes

This article has been dead for over six months. Start a new discussion instead.