random number help

This is a discussion on random number help within the C++ Programming forums, part of the General Programming Boards category; I am trying to simulate the rolling of a six sided die ten time...but get a compile error. Code: #include ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    89

    random number help

    I am trying to simulate the rolling of a six sided die ten time...but get a compile error.

    Code:
    #include <cstdlib>
    using std::rand;
    using std::srand;
    
    #include <iostream>
    using std::cout;
    using std::endl;
    
    #include <ctime>
    using std::time;
    
    
    int main()
    {
        const int arraysize = 7;
        int value[arraysize] = {0};
        
        srand( time( 0 ) ); // seed random number generator
        for( int roll = 1, roll <=10, roll++) // roll die 10 times
        value[ 1 + rand() % 6]++;
        cout << value << endl;
        
        system("PAUSE");
        return 0;
    }

    Errors:
    22 C:\Dev-Cpp\main.cpp expected init-declarator before '<=' token
    22 C:\Dev-Cpp\main.cpp expected `,' or `;' before '<=' token
    26 C:\Dev-Cpp\main.cpp expected `)' before ';' token

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    Take a look at the second error message and you'll get there.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    89
    yeah...got it

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    array indexes are zero based
    0,1,...6 are valid indexes, so why are you using 1..6?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 03:08 PM
  2. Random number in range generation.
    By hebali in forum C Programming
    Replies: 19
    Last Post: 03-04-2008, 10:46 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 01:56 PM
  4. random number tutorial
    By 7stud in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2005, 03:41 PM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 08:34 PM

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