I could use some help here... Yes, unfortunately it is homework, my C++ teacher thought it would be a treat to make us write a C lab for fun. Well C was years ago and I'm just stuck. I've tried this program about 5 different ways, have been working on it since last week and hate to bother anyone, but I'm desperate for some help. My extremely messy nested if statement seems to be causing the problem. It seems necessary to me though. The program compiles with no warnings and no errors, but doesn't run. Any assistance would be greatly appreciated. Thank you so much.
Heather.
#include <stdio.h>
#include <conio.h>
int main (void)
{
/* local definitions */
int seatNum1 = 0;
int seatNum2 = 0;
int seatNum3 = 0;
int seatNum4 = 0;
int seatNum5 = 0;
int seatNum6 = 0;
int answer = 0;
char answer2 = 'n';
char lastName [10];
char firstName [10];
/* list seat numbers */
printf("Welcome to Wheezer Airless... where smoking is encouraged!\n");
printf("Seats on aircraft are 1, 2, 3, 4, 5, and 6.\n");
printf("First class seats are seats 1 and 2.\n\n");
/* add passenger */
printf ("Would you like coach or first class? (1 for first 2 for coach)\n");
fflush(stdin);
scanf("%d", &answer);
if (answer = 'c')
{
if (seatNum3 == 1, seatNum4 == 1, seatNum5 == 1, seatNum6 == 1)
printf("No seats are available!");
else if (seatNum3 = 1, seatNum4 = 1, seatNum5 = 1, seatNum6 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum6 = 1;
}
else if (seatNum3 = 1, seatNum4 = 1, seatNum5 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum5 = 1;
}
else if (seatNum3 = 1, seatNum4 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum4 = 1;
}
else if (seatNum3 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum3 = 1;
}
}
else if (answer = 'f')
{
if (seatNum1 = 1, seatNum2 = 1)
{
printf("No first class available, would you like coach? (y or n)\n");
scanf("%c", answer2);
}
if (answer2 = 'y')
if (seatNum3 = 1, seatNum4 = 1, seatNum5 = 1, seatNum6 = 1)
printf("No seats are available!");
else if (seatNum3 = 1, seatNum4 = 1, seatNum5 = 1, seatNum6 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum6 = 1;
}
else if (seatNum3 = 1, seatNum4 = 1, seatNum5 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum5 = 1;
}
else if (seatNum3 = 1, seatNum4 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum4 = 1;
}
else if (seatNum3 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum3 = 1;
}
else if (answer2 = 'n')
printf("Please try another airline, thank you.\n");
}
else if (seatNum1 = 1, seatNum2 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum2 = 1;
}
else if (seatNum1 = 1, seatNum2 = 0)
{
printf("Please enter last name:\n");
scanf("%c", lastName);
printf("Please enter first name:\n");
scanf("%c", firstName);
printf("%c %c your seat number is 6. \n", firstName, lastName);
seatNum1 = 1;
}
else
return 0;
printf("Would you like to exit?");
return 0;
}
Program Specs: (if curious) =)
Our airplane holds 6 passengers... 2 in First Class... 4 in Coach class.. As Passengers arrive at the gate the system should take and record the last name and assign a seat number (1 thru 6 ) 1 and 2 being First Class.
People requesting Coach get a Coach seat. If Coach is full, then they are out of luck and must go elsewhere.
People requesting First Class get a First Class seat unless First Class is full in which case they are offered Coach unless Coach is also full in which case they too, must go elsewhere.
The program should start by offering a menu of choices to select.
WHEEZERS AIRLESS
1. List all seat assignments
2. Add a passenger to Coach
3. Add a passenger to First Class
4. Exit this program
SELECTION->
After performing each function the program returns to the menu until Exit option is selected.
DELIVERABLES: Including e-mailed labs
Fully documented listing of this and all future programs by doing the following:
1. Place a program abstract at the top of the program (class, or function not belonging to any class). This should tersely describe the item's purpose, input, output, and method/algorithm(s) used.
2. Put a comment to the right of each variable (or related group of variables) tersely describing its purpose.
3. Use meaningful identifiers (names for variables, constants, classes, functions, etc.).
4. Put a comment above each group of logically-related statements that serve a well-defined purpose so as to make that purpose clear.
5. Place a comment at the top of your listing giving your name, course, and section.