Thread: control problem

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    8

    control problem

    hi all,

    I've done this code which has to book seats for a particular gala performance.

    Code:
    main()
    {
    int flag[100], num;
    
    //num=number of seats booked at a time
    //flag[i]=1 for seats that are booked
    //flag[i]=0 for seats still available
    
    //initially all 100 seats are available
    
    for(int i=0;i<100;i++)
    flag[i]=0;
    
    printf("Enter the number of seats to be booked : ");
    scanf("%d",&num);
    
    int j=0;
    
    while(!flag[j])
    {
    for(int k=0;k<num;k++)
    flag[k]=1;
    if (flag[k+num-j]==1)
    break;
    else
    {
    continue;
    j++;
    }
    This should first scan the array for elements with flag[] = 0 and set flag[ ] =1 for the elements encountered then on upto the limit specified by 'num'. But it is not doing so...suggestions anyone?

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    take out the else block, and just put "++j;"

    Read about continue, 'cause you're using it wrong.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    8
    Thanks for your reply, but it is still not getting there....

    I was working on a menu-based program which takes user input till it is asked to exit - it reserves empty seats, cancels already booked seats and displays available seats as per user choice.

    The availability and the cancellation parts can be done once the reservation one is.....
    Last edited by Kingsley; 07-11-2006 at 06:03 PM.

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    8

    actual problem

    The class Performance

    A class to describe the state of seats for an individual performance at a cinema. This class has the following methods:

    available - Return true if there are n seats available for the performance otherwise return false.

    book - Book n seats. The number of seats booked is returned, hence a result of 0 indicates failure.

    cancel - Cancel the booking for seats already booked.

    remaining - Return the number of seats not booked for this performance.

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    That seems to indicate you're to write a class, which is a feature of C++. This would be the C forum. At any rate, your above code makes no indication of a class. If you're to use C++ classes (as your previous post seems to imply), the least you could start with is a class with those members, even if they're empty.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit color depth bitmap problem with XP
    By kalabala in forum C++ Programming
    Replies: 0
    Last Post: 12-22-2008, 06:56 AM
  2. Problem with the control characters
    By vin_pll in forum C++ Programming
    Replies: 12
    Last Post: 10-22-2008, 07:28 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Subclassing edit control - slight problem
    By Shag in forum Windows Programming
    Replies: 3
    Last Post: 11-03-2002, 12:33 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM