greetings everyone,
i seem to be having an issue with a function that has a reference n a value to do a loop. the nature of the prog, is to roll a dice (n) times n then count the number of time srand rolls an even num.
for the most part i think it is working--no errors, but inside a function im calling another function n then asking it to loop. And that is where im stuck @.
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int simDiceThrow(int, int&);
int diceThrow(int&);
bool isEvenSided(int&);
const long MAX=6, MIN=1;
int main ()
{
int diceA,
total=0,
totalOne=0,
pvalue,
maxNumber=0;
srand((unsigned)time(NULL));
cout <<" Dice Counter\n\n";
maxNumber = 100;
simDiceThrow(maxNumber, pvalue);[QUOTE]not sure if error is here as the MaxNum should be getting passed to the loop inside the function[/QUOTE]
if (isEvenSided(pvalue) != false) {total++;}
maxNumber = 1000;
simDiceThrow(maxNumber, pvalue);[QUOTE]im wondering how will the if statement run if there is no loop outside??[/QUOTE]
if (isEvenSided(pvalue) != false) {totalOne++;}
cout <<"100 x dice thrown "
<<" " <<total <<" " <<pvalue;
cout <<"\n1000 x dice thrown"
<<" " <<totalOne <<" " <<pvalue;
_flushall();
cin.get();
return 0;
}
int diceThrow (int &diceA)
{
return (diceA = (rand() % (MAX - MIN +1))+ MIN);
}
bool isEvenSided (int &pvalue)
{
return ((pvalue%2)== 0);
}
int simDiceThrow(int maxNumber, int &diceA)
{
int pvalue;
for (int roll = 0; roll < maxNumber; roll++) {pvalue = diceThrow(diceA);}
return pvalue;
}
any suggestions are greatly appreciated.