Thread: Question about c program

  1. #16
    Registered User
    Join Date
    Apr 2012
    Posts
    44
    But I need this data to be represented in a grid of rows and columns. Vacant spaces should be marked as '-' , while taken spaces should be 'O'. Program must prompt user to enter row and column , and check whether space is vacant , if it is vacant , the user can enter new entry. I want it to look something like this :

    Section 1
    1 2 3 4 5 6 7 8 9 10
    1 - - - - - - - - - -
    2 - - - - - - - - - -
    3 - - O - - - O - - -
    4 - - - - - - - - - -
    5 - - - - - - - - - -
    6 - - - - - O - - - -
    7 - - - - - - - - - -
    8 - - - - - - - - - -
    9 - - - - - - - - - -
    10- - - - - - - - - -

    Now this has to be repeated for each 5 sections.
    Last edited by TexasKid; 04-21-2012 at 10:20 AM.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So change your print function - it's not that hard if you've got this far.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Indeed! This is simple compared to the stuff you already did.

    You already have the loops right:

    Code:
    for (i = 0; i < 10; i++)      // go through each row
      {
        for (k = 0; k < 10; k++)    // for each row, go through each column
        {
    So in here you just want to print the char isFree. So don't use %s, use %c for a char.

    That'll print the chars in a long string. Getting it into a grid is easy - just print a newline in the outer loop. Then mess with the spacing until you're happy.

  4. #19
    Registered User
    Join Date
    Apr 2012
    Posts
    44
    haha you just pin-pointed my problem. I dont' know where I need to print the isFree char

  5. #20
    Registered User
    Join Date
    Apr 2012
    Posts
    44
    How can I go about relating each entry in the array to an '-' or 'O' in the grid , so that each '-' or 'O' represents a record ? How can the grid can then be printed ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question on C program
    By tekkiram in forum C Programming
    Replies: 6
    Last Post: 04-19-2010, 06:45 AM
  2. Help to program for this question
    By khamarutheen in forum C Programming
    Replies: 1
    Last Post: 01-19-2006, 01:34 AM
  3. Program question!?!?!?!
    By RealityFusion in forum C++ Programming
    Replies: 12
    Last Post: 04-15-2004, 02:02 AM
  4. Got a question about a program...
    By Phantasmagoria in forum Game Programming
    Replies: 1
    Last Post: 12-19-2003, 09:32 PM
  5. Program question---
    By d21998 in forum C++ Programming
    Replies: 13
    Last Post: 05-20-2002, 07:21 PM