Thread: A problem related to array

  1. #1
    Registered User
    Join Date
    Jan 2012
    Location
    Singapore
    Posts
    2

    Question A problem related to array

    How to print out the 2D array(an airplane seat layout) as follow (at the beginning, all numbers are 0)and if the user input A1(row1,column1), the program will automatically choose the seat, if the user doesn't input anything, the program will randomly choose one seat available. Then, the program will refresh the table when the next user choose again.
    Note: "0" represents seat available while "1" not available
    A problem related to array-qq-20120109124312-png

    Thank you!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You could associate the A row with 0 row, in the array. Char's can be used like small int's - subtract 'A' from the letter of the row, and that's your row number in the array.

    Your array is missing row N, just FYI.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Location
    Singapore
    Posts
    2
    Quote Originally Posted by Adak View Post
    You could associate the A row with 0 row, in the array. Char's can be used like small int's - subtract 'A' from the letter of the row, and that's your row number in the array.

    Your array is missing row N, just FYI.
    Thanks for your correction.
    How can i randomly choose any seat in the array?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You slipped right by me!

    The rows letters are now associated with the numbers 0 through 15 with 13 being skipped (A-P, but no N).

    So you can now use rand() % 16, for the row number (which you will then change into the proper letter), and rand() % 6 + 1, which will give you the random column number. You'll need to include stdlib.h for rand(), and you should know that random numbers will randomly repeat - if so, you need to work that out, what to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer related problem
    By shashinitjsr in forum C Programming
    Replies: 2
    Last Post: 06-25-2011, 02:37 AM
  2. Widget problem [GTK RELATED]
    By darekg11 in forum C Programming
    Replies: 5
    Last Post: 05-09-2011, 12:25 PM
  3. Replies: 12
    Last Post: 10-22-2006, 08:37 PM
  4. A problem related to DB and C using SQLAPI++
    By redhunter in forum C Programming
    Replies: 0
    Last Post: 05-12-2004, 10:14 AM
  5. Question related to array and pointers
    By Q4u in forum C++ Programming
    Replies: 6
    Last Post: 07-26-2002, 12:54 PM