Here is my assignment:
Write a C program that will reserve seats on an airplane that has 10 first class seats and 100 coach seats. Your program should be menu driven.
If a seat of the desired type is available, your program should recored the reservation and display the seat number. If the user wants a fa seat and none are available, the program should display a menu to help them book another class. When all of the seats are taken, the program should display a message and terminate.
THe array should be initialized with an 'a' in each cell to indicate that the seat is available. WHen the seat is reserved, the 'a' should be changed to an 'r'.
So here is all I have so far. I try to use the counter i so every time I call the option 1, it will increase and recorded itself into the array. But seems to be not working since every time I test, it is always 0.
And for the 'a' and 'r' part, I did a little research and it seems to be I need to use a 2D array. But i'm not quite sure how a char can stay in an integer array. I'm newbie with coding ( 1st time) so any help is appreciated :). Thanks !
ps: The coach class is pretty much the same to the first class so I think it is easier to see if I dont show that


#include <stdio.h>

void main()
{	int choice, i=0, counter=0;
  	int fclass[10];
	printf("Welcome to the booking program");
		printf("\n Please pick one of the following option:");
		printf("\n 1) Reserve a first class seat on Flight 101.");
		printf("\n 2) Reserve a coach seat on Flight 101.");
		printf("\n 3) Quit ");
		printf("\n ---------------------------------------------------------------------");
		printf("\nYour choice?");
			case 1:

				if (i <10){
						printf("Here is your seat: %d " , fclass[i]);
				else if (i = 10)
						printf("Sorry there is no more seat. Please wait for the next flight");
			case 3:
				printf("Thank you and goodbye\n");
	} while (choice != 3);

I prefer 'for loops' for counting myself.

Say you want to count/loop something.

For a while loop:

while (count<= 5) {
printf("%i\n", count);

By declaring the number to count inside the loop, it counts each time the loop processes.

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