Thread: Array Testing problem

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    Array Testing problem

    Ok heres the deal my program compiles fine. But when I run it I get nothing coming up in the console window. I would apreciate any help.

    Code:
    int main()
    {srand ( time(NULL) );
    
     for(i=5; i++;)
     { for(int x=0; x=4; x++)
       {chro[i][x]=rand()%30;  
       }  
     }
    
    /*****Test******/
    for(int g=0;g=5;g++)
    { for(int h=0; h=4; h++)
      {cout<<"Chro["<<g<<"]["<<h<<"]="<<chro[g][h];
       cout<<"\n";
      }
    }
    /*****Test******/
          cout<<"\n";
          system("PAUSE");
          return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Add a "<" to your for loop.

    Code:
    for(int g=0; g <=5; g++)
    {
    }
    Kuphryn

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    208

    thanx that worked

    but I was wondering something else how can I make the dos window come out bigger it is too small to display my results. I figured I would post it here instead of creating a new thread
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208
    I also keep getting 0s generated for my random numbers
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by kas2002
    I also keep getting 0s generated for my random numbers
    Of course. rand() % 30 generates numbers in the interval 0-29. If you want 1-30, use (rand() % 30) + 1.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    208
    sorry I didn't explain myself good what I meant was that when it outputs the contents of my array every single number is a zero even when I put the +1 in. Which is weird cause logically they should come out to at least 1?? any ways I have reposted my source (well the main function anyways I haven't got too far on the other ones yet because of these stupid array problems)
    Code:
    int main()
    {srand ( time(NULL) );
    
     for(i<=4; i++;)
     { for(int x=0; x<=3; x++)
       {chro[i][x]=rand()%30+1;
       }  
     }
    
    /*****Test******/
    for(int g=0;g<=4;g++)
    { for(int h=0; h<=3; h++)
      {cout<<"Chro["<<g<<"]["<<h<<"]="<<chro[g][h];
       cout<<"\n";
      }
    }
    /*****Test******/
          cout<<"\n";
          system("PAUSE");
          return 0;
    }
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Where do you define chro?
    Code:
    int main()
    {
       srand(time(NULL));
    
       for(i<=4; i++;) //Should be for(int i=0; i<=4; i++)
       {
          for(int x=0; x<=3; x++)
          {
             chro[i][x] = (rand() % 30) + 1;
          }  
       }
    
       /*****Test******/
       for(int g=0; g<=4; g++)
       {
          for(int h=0; h<=3; h++)
          {
             cout << "Chro[" << g << "][" << h << "]=" << chro[g][h];
             cout << "\n"; //Valid, but I would use cout << endl; instead
          }
       }
    
       /*****Test******/
       cout << "\n";
       system("PAUSE");
       return 0;
    }
    Last edited by Magos; 10-19-2002 at 07:36 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    208

    Thanks

    that worked jeez that was all what I assumed to be the easy part of my code lol.
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple array of char array problem
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2006, 12:04 PM
  2. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM