Thread: help

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    7

    help

    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>

    using namespace std;

    const int size_x = 25;
    const int size_y = 2;
    int field[size_x][size_y];


    void location(int& size_x, int& size_y);

    int main ()
    {
    srand((unsigned) time(NULL));
    cout << fixed << showpoint << setprecision(5);
    for ( int i = 0; i < size_x; ++i )
    {
    for (int i = 0; i <size_y; ++i)
    {
    cout << size_y <<" " << rand() % 10;
    cout << size_x <<" " << rand() % 2 << endl;
    }
    }

    return 0;
    }

    //location function
    void location(int& size_x, int& size_y)
    {

    }

    can any one help. the output supose to be only two lines with both size_x and size_y being randome numbers.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Can you show an example of the output you're looking for?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    7
    somthing like:
    1 2
    2 10
    1 15
    1 18
    2 2

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Well, what you're doing now is printing size_y (2), then a random number, then size_x (25) and then another random number. It seems like you only need to avoid printing size_y and size_x:
    Code:
    #include <cstdlib>
    #include <ctime>
    
    using namespace std;
    
    const int size_x = 25;
    const int size_y = 2;
    int field[size_x][size_y];
    
    int main ()
    {
      srand((unsigned)time(NULL));
    
      for (int i = 0; i < size_x; ++i)
      {
        for (int i = 0; i <size_y; ++i)
        {
          cout<< rand() % 10 <<" "<< rand() % 2 <<endl;
        }
      }
    
      return 0;
    }
    Though I'm still slightly confused as to the purpose of this, so I could be wrong in my assumption.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    7
    thanks alot man now i have to do is get it to loop 25 times
    and maybe try to use a fucntion to check if the numbers hae been plooted twice and print those numbers.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >now i have to do is get it to loop 25 times
    It does already. The loop goes from 0 to size_x - 1. Because size_x is 25, there are 25 iterations of the outer loop.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed