Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 9th, 2005, 3:15 PM   #1
joker209
Newbie
 
Join Date: Mar 2005
Posts: 20
Rep Power: 0 joker209 is on a distinguished road
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
joker209 is offline   Reply With Quote
Old Apr 9th, 2005, 3:27 PM   #2
brkstf
Programmer
 
brkstf's Avatar
 
Join Date: Feb 2005
Posts: 89
Rep Power: 4 brkstf is on a distinguished road
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
brkstf is offline   Reply With Quote
Old Apr 10th, 2005, 4:45 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You're also missing a semicolon and several braces.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 10th, 2005, 11:19 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC