![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 20
Rep Power: 0
![]() |
airline reserve system
I am trying to write a airline reserve system like program, I have to write a program to assign seats on each flights (10 max for each flight)
u ask the user to type either 1 or 2, 1 for 1st class and 2 for coach. seats 1-5 is first class and 6-10 is coach, then after they input the type the programs prints out the passengers seat and whether its 1st class or coach. when 1st class is full, the program should ask if the passenger wants coach or wait for next flight and vise versa. if they want next flight print out next flight leaves in 3 hours.
#include <stdio.h>
int main()
{
int seats [9],i,type,choice,first=0,econ=5;
printf("Please type 1 for \"first class\"\n");
printf("Please type 2 for \"economy\"\n");
scanf("%d", &type);
for(i=0; i<9; i++)
{
if(type == 1) {
seats[first]=0;
printf("your seat number is %d, first class\n");
first++;
}
if (type == 2) {
seats[econ]=5
printf("Your seat number is %d, economy class\n");
econ++;
}
printf("Please type 1 for \"first class\"\n");
printf("Please type 2 for \"economy\"\n");
scanf("%d", &type);
}
for(i=0; i<9; i++)
if (first == 4) {
printf("Type 2 for economy seat or 3 for another flight\n");
scanf("%d",&choice);
else if (econ ==9) {
printf("Type 1 for first class seat or 3 for another flight\n");
scanf("%d",&choice);
}
if (choice ==3) {
printf("Next flight leaves in 3 hours\n");
}
return 0;
}I try to write the program but it wont even run for some reason |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2005
Posts: 89
Rep Power: 4
![]() |
the first thing i notice is that your seat array only has 9 members, when it should have ten.
also, when you have a choice, don't input an INT when you could be inputting a CHAR. it's an error-checking thing that you will appreciate later. also, your printf syntax is wrong when outputting variables. jsut a little help. gotta go |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You're also missing a semicolon and several braces.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
this will help you out... I wrote it in C++ on purpose... (1: Mainly for a logical view of how it flows, 2: It can be rewritten in C fairly easy... just didn't want to do a hw assignment).
#include <iostream>
using namespace std;
#define MAXSEATS 10
int choice;
int seats[9] = {0};
int Reserve (void);
int main (void)
{
for (;;)
{
Reserve();
}
return 0;
}
int Reserve (void)
{
cout << "Enter seat preference (0 to EXIT, 1 for First Class, 2 for Coach): ";
cin >> choice;
cout << endl;
int found,i=0;
switch (choice)
{
case 1:
{
for (i=0; i <= 4 ; i++)
{
if (seats[i] == 0)
{
found=1;
seats[i]=1;
break;
}
}
if (found != 0)
{
found = 0;
cout << "First Class, seat " << i << " has been reserved for you" << endl;
}
else
{
char res;
cout << "First Class is full. Would you like to reserve a seat in Coach? (y/n): ";
cin >> res;
cout << endl;
switch (res)
{
case 'Y':
case 'y':
{
Reserve();
}
break;
case 'N':
case 'n':
{
cout << "Next flight leaves out in 3 hours." << endl;
}
break;
}
}
}
break;
case 2:
{
int found = 0;
int n = 5;
for (n=5; n <= 9 ; n++)
{
if (seats[n] == 0)
{
seats[n] = 1;
found=1;
break;
}
}
if (found != 0)
cout << "Coach seat " << n << " has been reserved for you" << endl;
}
break;
default:
exit(0);
}
return 0;
}
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|