rollsize, rolls, results all need some data type - what are they?
Also, you cannot use the variable rollsize to set the size of the array - it must be a constant value (well, some compilers are letting you do this now, but it's not in C++ standard yet.)
In your for loop, when you get everything else fixed, you'll find it goes one step too far. Use strictly less than the actual array size for the comparison in the loop test i < 200
In the threedice.cpp, don't include onedie.h - you get that already from including threedice.h
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
void statistics (int rolls[];int rollsize; int rollresults [])
You're supposed to use commas to separate the parameters, not semicolons. And if that line is the start of a function where are the { and } at the beginning and end of the function?
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
At least one semicolon seems to be missing ...
int threedice::getsumFaces()
{
return die1.getroll()+die2.getroll()+die3.getroll() <strong>;</strong>
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
Post code. Its impossible for us to evalate the error messages without it.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
If there's a large amount you could just attach the code. Hit the "Go Advance" button, scroll down to load attachments.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
In your THREEDICE.H add the following forward declaration
#define THREEDICE_H
<strong>class onedie;</strong>
class threedice
...
Then the statistics() function is a bit odd, if you think it will be called from e.g. main(),
it probably should look like
int main()
{
const int roll_count = 200;
int rolls[roll_count] = {0};
// I'm not actually sure what the allresults should be
int allresults[roll_count] = {0};
// Then you can make the statistics() call ...
statistics (rolls, roll_count, allresults);
return 0;
}
void statistics (int rolls[], int count, int allresults[])
{
threedice tryerluck;
for(int i=0;i<count;i++)
{
tryerluck.rollem();
rolls[i]= tryerluck.getsumFaces();
}
// and maybe do something here with the allresults too
}
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
I got it to compile without error. Problem seems to be here
#ifndef THREEDICE_H
#define THREEDICE_H
#include "onedie.h" // <<<<<<<<<<<<<<<<<< ADD THIS LINE
class threedice
{
public:
void rollem();
int getsumFaces();
private:
onedie die1;
onedie die2;
onedie die3;
};
#endif
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Either you didn't know that you should use braces, or you forgot.
for (int i=0;i<rollsize;i++)
{
switch (rolls[i])
{ // Forgot this
case 3:allresults[0] = allresults [0]+1; break;
case 4:allresults[1] = allresults [1]+1; break;
/* ......... */
case 17:allresults[14] = allresults [14]+1; break;
case 18:allresults[15] = allresults [15]+1; break;
} // And this
}
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
you don't need that switch statement at all
for (int i=0;i<rollsize;i++)
{
allresults[i] = allresults [i]+1;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343