shortening!!?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 1051109210
    New Member
    • Mar 2007
    • 29

    #1

    shortening!!?

    Code:
    if (seat[0][0]=="X" && 
        seat[1][0]=="X" &&
        seat[2][0]=="X" &&
        seat[3][0]=="X" &&
        seat[4][0]=="X" &&
        seat[5][0]=="X" && 
        seat[6][0]=="X" &&
        seat[0][1]=="X" &&
        seat[1][1]=="X" &&
        seat[2][1]=="X" &&
        seat[3][1]=="X" &&
        seat[4][1]=="X" &&
        seat[5][1]=="X" &&
        seat[6][1]=="X" &&
        seat[0][2]=="X" &&
        seat[1][2]=="X" &&
        seat[2][2]=="X" &&
        seat[3][2]=="X" &&
        seat[4][2]=="X" &&
        seat[5][2]=="X" &&
        seat[6][2]=="X" &&
        seat[0][3]=="X" &&
        seat[1][3]=="X" &&
        seat[2][3]=="X" &&
        seat[3][3]=="X" &&
        seat[4][3]=="X" &&
        seat[5][3]=="X" &&
        seat[6][3]=="X")
    how can i shorten this piece?
  • dfound
    New Member
    • Jan 2007
    • 52

    #2
    Now, if your array is seat[6][3]
    Well , I think this might do....

    int flag=1;

    for(int i=0;i<6;i++) //For rows
    {
    for(int j=0;j<3;j++) //For columns
    if(ar[i][j]!='X')
    flag=0;
    }

    if(flag==0)
    //means that all the array is not X


    I am not sure but it might do the trick....

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      That should do it. You can also use a bool variable, but they'll essentially do the same thing. (Actually, since a bool variable is counted as an integreal value, they might be exactly the same).

      Comment

      Working...