Hello ,
My program works fine but I still have one error that appears and I would like to fix it. It is complaining about
srand( time(0) );
with the following error:
.cpp(25) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
My code is the following:
// contains the function prototypes for
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
#include "Dice.h"
//constructor to initialize results array
Dice::Dice(const int sumsArray[])
{
// initialize the elements of the array results to 0
for(int i = 0; i < possibleSums; i++)
results[i] = sumsArray[i];
}
void Dice::rollDice()
{
srand( time(0) );
for( int i = 0; i < 36000; ++i )
{
int sum = 0;
sum += rand() % 6 + 1;
sum += rand() % 6 + 1;
++ results[sum];
}
}
void Dice::displayMessage()
{
cout
<< "Sum Count" << endl
<< "-------------" << endl;
for( int i = 2; i <= 12; ++i )
{
cout
<< setw(3) << i << ": "
<< setw(7) << results[i] << endl;
}
}