The problem that i am facing is that when i choose economy class i have to choose it five times before it assigns me a seat. what do i have to change so if i choose economy it assigns me a seat the first time and assigns the seat in the right range which is from seats[5] and up.
Here is my code sorry if its a bit messy.
#include<stdio.h>
#include<stdlib.h>
void heading();
int main()
{
int seats [10] = {1,2,3,4,5,6,7,8,9,10};
int classChoice;
int choice;
int counter;
heading();
for (counter = 0; counter < 10; counter++ )
{
printf("First Class or Economy (First = 1 Economy = 2): ");
scanf("%d", &classChoice);
printf("\n\n");
if(classChoice == 1)
{
if(seats[counter] <= 5)
{
printf("Seat Number is %d.\n", seats[counter]);
printf("You are located in First Class.\n\n");
seats[counter];
}
else if(seats[counter] >= 5)
{
printf("The First seats are full.\n");
printf("We can move you to Economy if you like.\n");
printf("Please enter a 1 for yes or 2 for no : ");
scanf("%d", &choice);
printf("\n\n");
if(choice == 2)
{
printf("Please wait 3 hours for next flight.");
}
else if(choice == 1)
{
if(seats[counter] > 5)
{
printf("Seat Number %d.\n", seats[counter]);
printf("You are located in Economy Class.\n\n");
seats[counter];
}
else if(seats[counter] > 10)
{
printf("The Economy seats are full.\n");
printf("Please wait 3 hours for the next flight.\n");
}
}
}
}
if(classChoice == 2)
{
if (seats[counter] > 5)
{
printf("Seat Number %d.\n", seats[counter]);
printf("You are located in Economy Class.\n\n");
seats[counter];
}
else if(seats[counter] > 10)
{
printf("The First seats are full.\n");
printf("We can move you to First if you like.\n");
printf("Please enter a 1 for yes or 2 for no : ");
scanf("%d", &choice);
printf("\n\n");
if(choice == 2)
{
printf("Please wait 3 hours for next flight.\n");
}
else if(choice == 1)
{
if(seats[counter] <= 5)
{
printf("Seat Number is %d.\n", seats[counter]);
printf("You are located in First Class.\n\n");
seats[counter];
}
else if(seats[counter] > 5)
{
printf("The First Class section is also full.\n");
printf("Next flight leaves in 3 hours.\n");
}
}
}
}
}
return 0;
}
void heading()
{
printf("This program is a Airline Reservation System.\n");
printf("It asks the user to choose between First and Eco class.\n");
printf("The user then gets assigned a seat number and class based on the seat.\n\n");
}