Thank you skatamatic for that suggestion on the modulus (%). Narue I realized I had omitted the <ctime> and <cstdlib> libraries. After adding them it made it easier for me to identify the other errors.
As the program stands right now; it has finally compiled but I do not get random numbers between 1 and 53, as it should. I am getting an extremely large number out of range
(- 858993460). I get 6 of the same numbers.
Any suggestions?
The modified function definitions are:
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include "lottery.h" // include definition of class lottery
// constructor for the Lottery
Lottery::Lottery()
{
} // end of Lottery constructor
bool Lottery::checkLottery(int lotnum, int lottery_numbers[6])
{
for (int i=0; i < 6; i++)
{
lottery_numbers[i] = i * i; //store lottery numbers in the index
if (lottery_numbers[i] == lotnum || lottery_numbers[i] == 0)
{
return false;
}
}
return true;
}
void Lottery::setLottery(int lottery_numbers[6])
{
lotNumbers[6] = lottery_numbers[6];
}
int Lottery::getLottery()
{
return lotNumbers[6];
int lot_count = 0; // counter for the number of valid lottery numbers found
while (lot_count < 6)
{
time_t t;
srand(unsigned (time(&t)));
int lotnum = 1 + rand() % 53;
if (checkLottery(lotnum, lotNumbers))
{
lotNumbers[lot_count] = lotnum;
lot_count++;
}
}
}
void Lottery::displayLottery(int [])
{
getLottery();
for (int j = 0; j < 6; j++)
{
cout << getLottery() << " " << endl;
}
}
Last edited by Narue; Nov 14th, 2008 at 2:35 pm. Reason: added code tags