I was wondering if any of you C gurus would mind checking out my assignment that's due on Tuesday. It seems to run fine and I think I have it completed but wouldn't mind if some of you guys kind of proof read it and make sure I've done things correctly. Take into consideration we have just been using printf and scanf and basic control structures.
I would greatly appreciate it if anyone has any insight that could help me.Code:/* Airline Reservation System */ #include <stdio.h> #define SIZE 10 void reserve_first_class(int [], int); void reserve_economy(int [], int); int main(void) { int seats[SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int choice; printf("Please type 1 for \"first class\"\n"); printf("Please type 2 for \"economy\"\n"); printf("Enter -99 to end>>>"); scanf("%d", &choice); while(choice != -99) { if(choice == 1) { reserve_first_class(seats, SIZE); } else if(choice == 2) { printf("You chose choice 2\n\n"); reserve_economy(seats, SIZE); } else printf("\n\nPlease Select A Valid Choice!!\n\n"); printf("Please type 1 for \"first class\"\n"); printf("Please type 2 for \"economy\"\n"); printf("Enter -99 to end>>>"); scanf("%d", &choice); } return 0; } void reserve_first_class(int s[], int size) { int i, seat = 0; char decision; for(i = 0; i < size/2; i++) { if(s[i] == 0) { s[i] = 1; printf("\n\nYou have a seat, Your flight will leave shortly\n\n"); seat = 1; break; } else continue; } if(seat == 0) { printf("\nThere are no more available First Class seats\n"); printf("Would you like a seat in Economy? (Y or N) \n"); printf(">>>"); scanf(" %c", &decision); if(decision == 'y' || decision == 'Y') reserve_economy(s, size); else printf("\nNext flight leaves in 3 hours!\n\n"); } } void reserve_economy(int s[], int size) { int i, seat = 0; for(i = size/2; i < size ; i++) { if(s[i] == 0) { s[i] = 1; printf("\n\nYou have a seat, Your flight will leave shortly\n\n"); seat = 1; break; } else continue; } if(seat == 0) printf("\n\nSorry the flight is currently full\n\n"); }



LinkBack URL
About LinkBacks



