Hello -
I am new to C++ and working on a random generator to create 5 numbers and place them in my populateLottery Array. For some reason, the only subscript/element getting populated is element[0}. My count that I'm using is jumping from 0 to 5 in my "for" loop. I'm stumped as I've used the "for" loop before. I thought maybe a second set of eyes would help me. My MAX_LOTTO is a constant set to "5" and "count" is my counter, initialized to 0.
//Seed the generator to create random numbers each time program executes.
srand ( time( 0 ) );
int populateLottery[MAX_LOTTO] = {0}; //Populate the Array
for (int count = 0; count < MAX_LOTTO; count++); //This is the problem area
{
populateLottery[count] = rand() % 10; //random numbers from 0-9
}
int MAX_LOTTO = 5;
srand ( time( 0 ) );
int populateLottery[MAX_LOTTO]; //Populate the Array
for (int count = 0; count < MAX_LOTTO; count++) //This is the problem area
{
populateLottery[count] = rand() % 10; //random numbers from 0-9
}
I will edit it to be nice after you add code tags.
Hi - Thanks for the reply - this is what I have and I still am not getting my elements in my lottery array populated, with the exception of element[0]. Thank you for your help!
#include <iostream>
#include <iomanip>
#include <cstdlib> // For the random number generator pg. 129 in text book
#include <ctime> // This is needed for the time function (to generate nums)
using namespace std;
int main()
{
//Declare the variables and the arrays
const int MAX_LOTTO = 5;
const int MAX_USER = 5;
int lottery[MAX_LOTTO]; //Array for lottery nums
int user[MAX_USER]; //Array for user nums
//Seed the generator to create random numbers each time program executes.
srand ( time( 0 ) );
OK. Sorry...I understand now. I removed the ";" from my "for loop" and at least I'm now getting my array populated. It is not getting populated with 0-9 values but instead double digits. But at least I have something now. thank you!
#include <iostream>
#include <iomanip>
#include <cstdlib> // For the random number generator pg. 129 in text book
#include <ctime> // This is needed for the time function (to generate nums)
usingnamespace std;
int main()
{
//Declare the variables and the arrays
constint MAX_LOTTO = 5;
constint MAX_USER = 5;
int lottery[MAX_LOTTO]; //Array for lottery nums
int user[MAX_USER]; //Array for user nums
//Seed the generator to create random numbers each time program executes.
srand ( time( 0 ) );
int lottery[MAX_LOTTO]; //Populate the Array
for (int count = 0; count < MAX_LOTTO; count++)
{
lottery[count] = rand() % 10; //random numbers from 0-9
}
return 0;
}