Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Through this programming assignment, the students will learn to do the following: Know how to use a Makefile. Perform basic C commands. Use arrays, integers

Through this programming assignment, the students will learn to do the following:

Know how to use a Makefile.

Perform basic C commands.

Use arrays, integers and strings.

This assignment asks the user to write a program to assign seats in an airplane. There will be 12 seats on the plane, 4 in first class and 8 in economy. Initialy all seats are empty.

The program should display the following menu for the user in a loop until the user types 0 to quit:

Please type 1 for "first class" Please type 2 for "economy" Please type 0 to quit

If the user types 1 then the user should be assigned a seat in first class. If the user types 2 then the user should be assigned a seat in economy.

The program should not assign a seat that has already been assigned. If all seats in the desired section are taken, but there are available seats in the other section, then the user should be asked if they want a seat in the other section.

If the user says no, tell them "The next flight will be tomorrow."

Otherwise give them a seat in the other section.

The program should print a line indicating the seat the person was assigned. It would be a number from 1 to 12. This would be like a boarding pass.

You must use an array to represent the seats on the plane. This would be a one-dimentional array of size 12.

If the user types 0 as a choice the program should exit with a 0 return code since it is ended as requested.

Create a simple Makefile to compile your program into an executable called planeseats.

My Code so far:

#include

int main()

{

// Declerations

int firstClass = 1;

int economy = 5;

int planeCapacity[11];

int ticketSelection = 0;

int i = 0;

char answer;

// Asking Users which type of ticket they want.

printf("Enter 1 for First Class ");

printf("Enter 2 for Economy ");

printf("Enter 0 to quit ");

scanf("%d", &ticketSelection);

while (planeCapacity[i] <= 11)

{

// If user wants First Class ticket either assigns one if available, offers other class if First is booked and Economy has room, or tells user when next flight is.

if (ticketSelection == 1)

{

if (firstClass <= 4)

{

printf("Your seat assignment is First Class Seat: %d ", firstClass);

printf("Enjoy your flight! ");

firstClass = firstClass + 1;

planeCapacity[i]++;

}

if (firstClass > 4 && economy < 12)

{

printf("First Class is fully booked, would you like to book a seat in Economy? Y or N? ");

scanf("%s", &answer);

if ((answer == 'Y') || (answer == 'y'))

{

printf("Your seat assignment is Economy Seat: %d ", economy);

printf("Enjoy your flight! ");

economy = economy + 1;

planeCapacity[i]++;

}

if (answer == 'N' || answer == 'n')

{

printf("The next flight will be tomorrow ");

}

if ((answer != 'Y') && (answer != 'y') && (answer != 'N') && (answer != 'n'))

{

printf("Invalid Response, please try again. ");

printf("First Class is fully booked, would you like to book a seat in Economy? Y or N? ");

scanf("%s", &answer);

}

}

if (firstClass > 4 && economy > 12)

{

printf("Flight is fully booked. The next flight will be tomorrow. ");

}

}

// If user wants Economy ticket either assigns one if available, offers other class if Economy is booked and First has room, or tells user when next flight is.

if (ticketSelection == 2)

{

if (economy <= 12)

{

printf("Your seat assignment is Economy Seat: %d ", economy);

printf("Enjoy your flight! ");

economy = economy + 1;

planeCapacity[i]++;

}

if (economy > 12 && firstClass < 4)

{

printf("Economy is fully booked, would you like to book a seat in First Class? Y or N? ");

scanf("%s", &answer);

if (answer == 'Y' || answer == 'y')

{

printf("Your seat assignment is First Class Seat: %d ", firstClass);

printf("Enjoy your flight! ");

firstClass = firstClass + 1;

planeCapacity[i]++;

}

if (answer == 'N' || answer == 'n')

{

printf("The next flight will be tomorrow ");

}

if ((answer != 'Y') && (answer != 'y') &&(answer != 'N') && (answer != 'n'))

{

printf("Invalid Response, please try again. ");

printf("Economy is fully booked, would you like to book a seat in First Class? Y or N? ");

scanf("%s", &answer);

}

}

if (firstClass > 4 && economy > 12)

{

printf("Flight is fully booked. The next flight will be tomorrow. ");

}

}

if (ticketSelection == 0)

{

printf("Thank you for flying with C Airlines! ");

return 0;

}

if (ticketSelection > 2)

{

printf("Invalid Entry ");

}

printf("Enter 1 for First Class ");

printf("Enter 2 for Economy ");

printf("Enter 0 to quit ");

scanf("%d", &ticketSelection);

}

return 0;

}

Help Needed:

I keep having a problem where once a certain class fills up the program automatically ends itself. I don't know if I messed up my loop or what but I need the program to only end when 0 is entered. Thanks is advance for nay help!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Tell the merits and demerits of Mendeleev's periodic table.

Answered: 1 week ago