Thread: IF CONDITION plese help

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    IF CONDITION plese help

    You have 9 empty boxes in the beginning and you will fill these boxes with X characters.
    In the beginning
    You will take one row number and one column number between 1 and 3 from user in for each
    move, if user enters irrelevent input program will exit.
    If user enters as first move:
    row number: 2
    column number: 3
    X
    Then you will get second move from user:
    row number: 3
    column number: 1
    X
    X
    By this way you will fill in all boxes by taking totally 9 row and 9 column inputs from user.
    You must show each step to the user.
    If user enters the same row and column of the box which has already an X in it, program will
    exit.
    For example, for the following placement:
    X X
    X X
    X
    If user enters:
    row number: 1
    column number: 1
    You will warn user about her/his mistake and program will exit.
    You will use if condition statements, in your code.
    we are not allowed to use loop and array in this program

    Example outputs:
    Output #1:
    Game starts!
    123
    1| | | |
    2| | | |
    3| | | |
    Moves must be in row column form!
    Your move -->
    row: 1
    column: 3
    123
    1 | | |X|
    2| | | |
    3| | | |
    Your move -->
    row: 1
    column: 1
    123
    1 |X| |X|
    2| | | |
    3| | | |
    Your move -->
    row: 3
    column: 2
    123
    1 |X| |X|
    2| | | |
    3 | |X| |
    Your move -->
    row: 2
    column: 3
    123
    1 |X| |X|
    2 | | |X|
    3 | |X| |
    Your move -->
    row: 2
    column: 1
    123
    1 |X| |X|
    2 |X| |X|
    3 | |X| |
    Your move -->
    row: 3
    column: 3
    123
    1 |X| |X|
    2 |X| |X|
    3 | |X|X|
    Your move -->
    row: 2
    column: 2
    123
    1 |X| |X|
    2 |X|X|X|
    3 | |X|X|
    Your move -->
    row: 3
    column: 1
    123
    1 |X| |X|
    2 |X|X|X|
    3 |X|X|X|
    Your move -->
    row: 1
    column: 2
    123
    1 |X|X|X|
    2 |X|X|X|
    3 |X|X|X|
    Output #2:
    Game starts!
    123
    1| | | |
    2| | | |
    3| | | |
    Moves must be in row column form!
    Your move -->
    row: 2
    column: 3
    1 2 3
    1| | | |
    2 | | |X|
    3| | | |
    Your move -->
    row: 3
    column: 1
    1 2 3
    1| | | |
    2 | | |X|
    3 |X| | |
    Your move -->
    row: 2
    column: 3
    1 2 3
    1| | | |
    2 | | |X|
    3 |X| | |
    You entered wrong move! Game over!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I'm sure you'll enjoy coding it up.

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by birumut View Post
    we are not allowed to use loop and array in this program
    not cool
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    No one's going to do your work for you - make your best attempt, test it, and then post any problems you can't figure out and we'll help you from there.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    we are not allowed to use loop and array in this program
    Then are they teaching you to be a programmer or a lawyer? I could probably find ways of doing something that technically isn't strictly using an array, and one can use recursion instead of a loop. However the programmer in me says that this is just plain stupid!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    if condition

    ı do not want you to write my code, ı only want solution way,ı thought one way (using if )and now writing ,but it is very very long. ı know,may be you said your sentences for our goodness,
    ı would want to send my code,but ı thougt that it took very large places in forum.

    ı send one part but not "complete".if you explain ,where ı can write shorter (if,if else) ,ı will be happy...


    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
     int r,c ;  
    if(r==1 && c==1)
    {
       if(r==1 && c==2)
       {
        printf("   1 2 3\n");
        printf("1 |x|x| |\n");
        printf("2 | | | |\n");
        printf("3 | | | |\n");
           if(r==1 && c==3)
           {
            printf("   1 2 3\n");
            printf("1 |x|x|x|\n");
            printf("2 | | | |\n");
            printf("3 | | | |\n");
                if(r==2 && c==1)
                {
                 printf("   1 2 3\n");
                 printf("1 |x|x|x|\n");
                 printf("2 |x| | |\n");
                 printf("3 | | | |\n");
                    if(r==2 && c==2)
                    {printf("   1 2 3\n");
                     printf("1 |x|x|x|\n");
                     printf("2 |x|x| |\n");
                     printf("3 | | | |\n");
                     } 
                     else if(r==2 && c==3)
                     {printf("   1 2 3\n");
                      printf("1 |x|x|x|\n");
                      printf("2 |x| |x|\n");
                      printf("3 | | | |\n");
                      }
                      else if(r==3 && c==1)
                      {
                      printf("   1 2 3\n");
                      printf("1 |x|x|x|\n");
                      printf("2 |x| | |\n");
                      printf("3 |x| | |\n");
                      }
                      else if(r==3 && c==2)
                      {
                       printf("   1 2 3\n");
                       printf("1 |x|x|x|\n");
                       printf("2 |x| | |\n");
                       printf("3 | |x| |\n");
                       }
                       else if(r==3 && c==3)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 |x| | |\n");
                        printf("3 | | |x|\n");
                        }
                        else
                        printf("sorry\n");
                }  
                else if(r==2 && c==2)
                {
                 printf("   1 2 3\n");
                 printf("1 |x|x|x|\n");
                 printf("2 | |x| |\n");
                 printf("3 | | | |\n");
                       if(r==2 && c==1)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 |x|x| |\n");
                        printf("3 | | | |\n");
                       }
                       else if(r==2 && c==3)
                       {
                       printf("   1 2 3\n");
                       printf("1 |x|x|x|\n");
                       printf("2 | |x|x|\n");
                       printf("3 | | | |\n");
                       }
                       else if(r==3 && c==1)
                       {
                          printf("   1 2 3\n");
                          printf("1 |x|x|x|\n");
                          printf("2 | |x| |\n");
                          printf("3 |x| | |\n");
                       }
                       else if(r==3 && c==2)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | |x| |\n");
                        printf("3 | |x| |\n");       
                       }
                       else if(r==3 && c==3)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | |x| |\n");
                        printf("3 | | |x|\n");    
                       }
                       else 
                       printf("sorry\n");     
                }
                else if(r==2 && c==3)
                {
                printf("   1 2 3\n");
                printf("1 |x|x|x|\n");
                printf("2 | | |x|\n");
                printf("3 | | | |\n");
                       if(r==2 && c==1)
                       {printf("   1 2 3\n");
                       printf("1 |x|x|x|\n");
                       printf("2 |x| |x|\n");
                       printf("3 | | | |\n");
                       }         
                       else if(r==2 && c==2)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | |x|x|\n");
                        printf("3 | | | |\n");    
                       }
                       else if(r==3 && c==1)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | | |x|\n");
                        printf("3 |x| | |\n");  
                       }
                       else if(r==3 && c==2)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | | |x|\n");
                        printf("3 | |x| |\n");              
                       }
                       else if(r==3 && c==3)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | | |x|\n");
                        printf("3 | | |x|\n");    
                       }
                       else 
                       printf("sorry\n");
                }       
                else if(r==3 && c==1)
                {
                  printf("   1 2 3\n");
                  printf("1 |x|x|x|\n");
                  printf("2 | | | |\n");
                  printf("3 |x| | |\n");
                       if(r==2 && c==1)
                       {
                       printf("   1 2 3\n");
                       printf("1 |x|x|x|\n");
                       printf("2 |x| | |\n");
                       printf("3 |x| | |\n");      
                       }
                       else if(r==2 && c==2)
                       {
                         printf("   1 2 3\n");
                         printf("1 |x|x|x|\n");
                         printf("2 | |x| |\n");
                         printf("3 |x| | |\n");   
                       }
                       else if(r==2 && c==3)
                       {
                         printf("   1 2 3\n");
                         printf("1 |x|x|x|\n");
                         printf("2 | | |x|\n");
                         printf("3 |x| | |\n");   
                       }
                       else if(r==3 && c==2)
                       {
                       printf("   1 2 3\n");
                       printf("1 |x|x|x|\n");
                       printf("2 | | | |\n");
                       printf("3 |x|x| |\n");   
                       }
                       else if(r==3 && c==3)
                       {
                        printf("   1 2 3\n");
                        printf("1 |x|x|x|\n");
                        printf("2 | | | |\n");
                        printf("3 |x| |x|\n");   
                        }
                        else 
                        printf("sorry\n");
                }
                else if(r==3 && c==2)
                {
                 printf("   1 2 3\n");
                 printf("1 |x|x|x|\n");
                 printf("2 | | | |\n");
                 printf("3 | |x| |\n");
                        if(r==2 && c==1)
                        {
                         printf("   1 2 3\n");
                         printf("1 |x|x|x|\n");
                         printf("2 |x| | |\n");
                         printf("3 | |x| |\n");        
                        }
                        else if(r==2 && c==2)
                        {
                         printf("   1 2 3\n");
                         printf("1 |x|x|x|\n");
                         printf("2 | |x| |\n");
                         printf("3 | |x| |\n");  
                         }
                         else if(r==2 && c==3)
                         {
                         printf("   1 2 3\n");
                         printf("1 |x|x|x|\n");
                         printf("2 | | |x|\n");
                         printf("3 | |x| |\n");
                         }
                         else if(r==3 && c==1)
                         {
                           printf("   1 2 3\n");
                           printf("1 |x|x|x|\n");
                           printf("2 | | | |\n");
                           printf("3 |x|x| |\n");   
                         }
                         else if(r==3 && c==3)
                         {
                          printf("   1 2 3\n");
                          printf("1 |x|x|x|\n");
                          printf("2 | | | |\n");
                          printf("3 | |x|x|\n");  
                          }
                          else 
                          printf("sorry\n"); 
                }
                else if(r==3 && c==3)
                {
                 printf("   1 2 3\n");
                 printf("1 |x|x|x|\n");
                 printf("2 | | | |\n");
                 printf("3 | | |x|\n");
                          if(r==2 && c==1) 
                          { printf("   1 2 3\n");
                            printf("1 |x|x|x|\n");
                            printf("2 |x| | |\n");
                            printf("3 | | |x|\n");         
                          }
                          else if(r==2 && c==2)
                          {
                           printf("   1 2 3\n");
                           printf("1 |x|x|x|\n");
                           printf("2 | |x| |\n");
                           printf("3 | | |x|\n");   
                          }
                          else if(r==2 && c==3)
                          {
                          printf("   1 2 3\n");
                          printf("1 |x|x|x|\n");
                          printf("2 | | |x|\n");
                          printf("3 | | |x|\n"); 
                          }
                          else if(r==3 && c==1)
                          {
                            printf("   1 2 3\n");
                            printf("1 |x|x|x|\n");
                            printf("2 | | | |\n");
                            printf("3 |x| |x|\n");   
                          }
                          else if(r==3 c==2)
                          {
                          printf("   1 2 3\n");
                          printf("1 |x|x|x|\n");
                          printf("2 | | | |\n");
                          printf("3 | |x|x|\n");   
                          }
                          else 
                          printf("sorry\n");
                }
                else
                printf("sorry\n");
           }
            else if(r==2 && c==1)
            {
             printf("   1 2 3\n");
             printf("1 |x|x| |\n");
             printf("2 |x| | |\n");
             printf("3 | | | |\n");
             }
             else if(r==2 && c==2)
             {
             printf("   1 2 3\n");
             printf("1 |x|x| |\n");
             printf("2 | |x| |\n");
             printf("3 | | | |\n");
             }
             else if(r==2 && c==3)
             {printf("   1 2 3\n");
             printf("1 |x|x| |\n");
             printf("2 | | |x|\n");
             printf("3 | | | |\n");
             }
             else if(r==3 && c==1)
             {
             printf("   1 2 3\n");
             printf("1 |x|x| |\n");
             printf("2 | | | |\n");
             printf("3 |x| | |\n");
             }
             else if(r==3 && c==2)
             {
              printf("   1 2 3\n");
              printf("1 |x|x| |\n");
              printf("2 | | | |\n");
              printf("3 | |x| |\n");
             }
             else if(r==3 && c==3)
             {
              printf("   1 2 3\n");
              printf("1 |x|x| |\n");
              printf("2 | | | |\n");
              printf("3 | | |x|\n");
              }
      }       
       else if(r==1 && c==3)
       {
        printf("   1 2 3\n");
        printf("1 |x| |x|\n");
        printf("2 | | | |\n");
        printf("3 | | | |\n");
     
     }
       
       else if(r==2 && c==1)
       {
        printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 |x| | |\n");
        printf("3 | | | |\n");
       }
    
       else if(r==2 && c==2)
       {
        printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 | |x| |\n");
        printf("3 | | | |\n");
       }
       
       else if(r==2 && c==3)
       {
        printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 | | |x|\n");
        printf("3 | | | |\n");
       }
       
       else if(r==3 && c==1)
       {
        printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 |x| | |\n");
        printf("3 | | | |\n");
       }
       
       else if(r==3 && c==2)
       {printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 | | | |\n");
        printf("3 | |x| |\n"); 
       }
    
       else if(r==3 && c==3)
       {
        printf("   1 2 3\n");
        printf("1 |x| | |\n");
        printf("2 | | | |\n");
        printf("3 | | |x|\n");
       }                    
       else
       printf("sorry\n");
    }                                    
    
    
    
    
    
    getch();
    return 0;
    }

  7. #7
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Code:
    char r1c1, r1c2, r1c3;
    char r2c1, r2c2, r2c3;
    char r3c1, r3c2, r3c3;
    r1c1=r1c2=r1c3=r2c1=r2c2=r2c3=r3c1=r3c2=r3c3=' ';
      
    //find the row and column and set the corresponding char to 'x' (I did not include this)
    
      printf("   1 2 3\n");
      printf("1 |%c|%c|%c|\n", r1c1, r1c2, r1c3);
      printf("2 |%c|%c|%c|\n", r2c1, r2c2, r2c3);
      printf("3 |%c|%c|%c|\n", r3c1, r3c2, r3c3);
    I think %c is what you use to print chars
    Last edited by ಠ_ಠ; 03-06-2009 at 03:47 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    ricj - you just asking to use array rc[i][j]
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    If they're going to put poor restrictions like that... then use "goto". Fight fire with fire baby.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I think that being asked to write this without loops or arrays is actually some kind of sick joke, or perhaps a test. There are 9! (nine factorial = 362880) possible combinations of ways to fill this grid, and that's if you ignore the invalid moves! Otherwise it's 9^9 = 387420489 if statements your program would require!!! You can combine a few of the validity checks after a few moves, but it still wont get you under 1 million if-statements This must be a test and you're supposed to tell whoever gave you this most absurd assignment that it is absolutely insane. Either that or you misheard or misunderstood. Even writing a code generator to write the bulk of the code for you would be pretty stupid. We can't help you to do the impossible.

    Using loops and arrays it would take about 10 if-statements. You can simulate an array by using switchs statements though, if you're allowed to use that:
    Code:
    int r0c0, r0c1, r0c2, r1c0, r1c1, r1c2; //etc
    int lookup(int row, int col)
    {
        switch (row)
        {
            case 0:
            switch (col)
            {
                case 0:
                    return r0c0;
                break;
                case 1:
                    return r0c1;
                break;
                case 2:
                    return r0c2;
                break;
            }
            break;
            case 1:
            switch (col)
            {
                case 0:
                    return r1c0;
                break;
                case 1:
                    return r1c1;
                break;
                case 2:
                    return r1c2;
                break;
            }
            break;
            case 2:
            // etc...
            break;
        }
    }
    Last edited by iMalc; 03-06-2009 at 05:00 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    think mapping the coordinate to the value would break the rules? though it sounds like structures may not have been covered (or they have and you're teacher's a jerk)

    or why not write a program that spits out the code you need, then just don't tell your instructor that your solution was generated.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  12. #12
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quote Originally Posted by iMalc View Post
    Even writing a code generator to write the bulk of the code for you would be pretty stupid.
    ouch. shoulda refreshed page before replying
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  13. #13
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by neandrake View Post
    ouch. shoulda refreshed page before replying
    Stupid probably wasn't the right word for it. As fun or clever as it might be, it's just counter-productive here. This person is not being taught how to program, they're being taught how not to program!
    It's like being asked to produce a car with square wheels.
    Last edited by iMalc; 03-06-2009 at 09:51 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Condition variables
    By sethjackson in forum Windows Programming
    Replies: 16
    Last Post: 03-19-2008, 11:42 AM
  3. SDL Condition variables.
    By antex in forum Game Programming
    Replies: 3
    Last Post: 11-11-2005, 07:11 AM
  4. Looping condition
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 02:06 PM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 09:42 PM