I having trouble with my program. Here is my code:
// Airlines Reservation system
#include <stdio.h>
main()
{
int business[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // declaring array
int economy[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; // declaring array
int buscount = 0; // variable
int econocount = 0; // variable
int integer1; // variable
printf("Welcome to Sydney Airlines\n");
printf("Please choose 1 for business class or 2 for economy class or 3 to exit:"); //prompt
scanf("%d", &integer1); // reads the integer
printf("\n"); // inserts a new line
printf("\n"); // inserts a new line
// enter choice between business or economy class
// initializing business array
while(integer1 != 3) {
if(integer1 == 1){
if(buscount > 9){
printf("Switch to Economy");
break;
// Switches back to economy
econocount++;
printf("You are in seat %d, Economy", economy[econocount]);
printf("Would you like economy class? 1 = Y 2 = N:");
scanf("%d", &integer1);
} // this bracket belongs to the first if statement
printf("Welcome to Business Class\n");
buscount++;
printf("Your seat is %d", business[buscount-1]);
} // this bracket belongs to the second if statement
printf("\nEnter another? 1 = Y 2 = N\n");
scanf("%d", &integer1);
// this bracket belongs to the while loop
// initializing economy array
if(integer1 == 2){
if(econocount > 19){
printf("Switch to Bussiness");
// Swithches back to business
buscount++;
printf("You are in seat %d, Business", business[buscount]);
printf("Would you like economy class? 1 = Y 2 = N:");
scanf("%d", &integer1);
} // this bracket belongs to the first if statement
printf("Welcome to Economy Class\n");
econocount++;
printf("Your seat is %d", economy[econocount]);
} // this bracket belongs to the second if statement
printf("\nEnter another? 1 = Y 2 = N\n");
scanf("%d", &integer1);
// ends the program
if(integer1 == 3)
printf("Thank you for using the program\n");
} // this bracket is end the first while loop
return 0; // program excutes successfully
}
When I press 1 it goes through the business class until it gets to 10. Then the user gets a message if they want to switch to economy class. that works. But if I restart the program at economy class all I get is a message saying Enter 1 = Y 2 = N. What is wrong with the program. Can someone help me out plz