arrays of random integers & time

This is a discussion on arrays of random integers & time within the C++ Programming forums, part of the General Programming Boards category; Look at how many times you have { with out a mathcing }...

  1. #16
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Look at how many times you have { with out a mathcing }

  2. #17
    Registered User
    Join Date
    Dec 2004
    Posts
    11
    this runs 50 numbers how can i make it run 25 thru r0w and 25 thru col,this is killing me

    srand( (unsigned)time( NULL) );
    for(int times=0;times==25;times++)
    int a = 0;
    int b = 0;
    int array;
    for (int a = 0; a<25; a++)
    cout<<1 + rand() % 10 <<endl;
    {for(int b=0; b<25; b++)
    cout <<1 + rand() % 10 <<endl;}
    funcrand( a,b );
    return 0;

  3. #18
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Can you
    a) Please use [code][/code]Tags
    b) post the whole program, including whatever funcrand() function does.

  4. #19
    Registered User
    Join Date
    Dec 2004
    Posts
    11
    Quote Originally Posted by Salem
    Can you
    a) Please use [code][/code]Tags
    b) post the whole program, including whatever funcrand() function does.
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <time.h>
    using namespace std;
    const int numberofrows=25;
    const int numberofcolumns=25;
    int grid[25][25];
    void funcrand(int& row,int& col)
    {row=2;
     col=3;}
    void srand(unsigned int seed);
    	
    int main ( ) 
    {
    	srand( (unsigned)time( NULL) ); 
    	for(int times=0;times==25;times++)
    	int a = 0;
    	int b = 0;
    	int array; 
    	for (int a = 0; a<25; a++)
    	cout<<1 + rand() % 10 <<endl;
    	{for(int b=0; b<25; b++)
    	cout <<1 + rand() % 10 <<endl;}
    	funcrand( a,b );
    	return 0;
    }

  5. #20
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Your use of braces { and } is poor.

    For example, you wrote
    Code:
    for(int times=0;times==25;times++)
    	int a = 0;
    	int b = 0;
    Which to the compiler means this
    Code:
    for(int times=0;times==25;times++) {
    	int a = 0;
    }
    int b = 0;
    So the first step is to go through your code and put matching { and } around all the statements which you want to be executed as part of each for loop.

    Then you can work on the logic problems, of say why for(int times=0;times==25;times++) doesn't execute at all, whereas for(int times=0;times<25;times++) executes 25 times

  6. #21
    Registered User
    Join Date
    Dec 2004
    Posts
    11
    i dont understand u,where should i put the braces,maan i jus started c++

  7. #22
    Registered User
    Join Date
    Dec 2004
    Posts
    11
    Code:
    	srand( (unsigned)time( NULL) ); 
    	int a = 0;
    	int b = 0;
    	int array; 
    	for(int times=0;times<25;times++)
    	for(int a=0; a<25; a++)
        {
            for(int b=1; b<25; b++)
            {
                if(times == 10)
                {
                    cout <<1 + rand() % 10 <<endl;
                }
    		}
    	 }
    	funcrand( a,b );
    	return 0;

  8. #23
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    int myArray[5][10]; declares a static array of ints. It can conceptualized as a table with 5 rows on 10 ints per row. If you were to put a label on each row they would go from 0-4, and the columns would be labeled from 0-9. myArray[0][0] = 1; will assign the value one to the first int in the first row, whereas myArray[2][6] = 21; will assign the value of 21 to the 7th int in the third row. And myArray[x][y] will access the (y + 1) element of the (x + 1) row. Frequently, nested loops with the outer loop controlling the rows and the inner loop controlling the columns are used when dealing with this type of construct, but you can also deal with this as a single dimensional array if you wish. The math is a bit more convoluted to use unidimensional indexing, but it's actually closer to what the computer actually is doing.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 03:44 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  3. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  4. Adding arrays of integers in a node struct
    By emilyashu in forum C Programming
    Replies: 7
    Last Post: 04-26-2003, 06:19 PM
  5. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 03:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21