Okay, figured that much out but I'm getting compiler errors on my object (which has data members from another object)

void statistics (int rolls[];int rollsize; int rollresults [])
threedice tryerluk;
rollsize=200;
rolls[rollsize];
rollresults[16];

for (int i=0;i<201;i++)
{
   tryerluk.rollem();
   rolls[i]=tryerluk.getsumFaces();
}void statistics (int rolls[];int rollsize; int rollresults [])
threedice tryerluk;
rollsize=200;
rolls[rollsize];
rollresults[16];

for (int i=0;i<201;i++)
{
   tryerluk.rollem();
   rolls[i]=tryerluk.getsumFaces();
}

This gives me a heap of missing type specifier and syntax errors back in the threedice class data members (from class onedie) It says missing type specifier-int assumed C++ does not support default int. What am I missing? Could I have declared my classes wrong?

here is the onedie class header

class onedie
{
	public:
		void rollit();
		int getroll();

	private:
		int result;

};

here is the threedice class header

class threedice
{
	public:
		void rollem();  	  
		int getsumFaces();

	private:

		onedie die1;
		onedie die2;
		onedie die3;

};

Here is the onedie definition (member functions)

#include "onedie.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;


void onedie::rollit()
{
	srand(time_t(NULL));
	result= 1 + rand() % 6;
}

int onedie::getroll()
{
	return result;
}

and the threedice implementation

#include "onedie.h"
#include "threedice.h"
#include <iostream>

using namespace std;

void threedice::rollem()
{
        die1.rollit();
        die2.rollit();
        die3.rollit();
}

int threedice::getsumFaces()
{
         return die1.getroll()+die2.getroll()+die3.getroll()
}

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

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?

commented: very helpful, extremely patient +1

vmanes--my apologies, on my screen they are set as ints, and rollsize is a const int. Thanks for the tip on the loop, I thought since I needed 200 rolls it should go to 201, but I wasn't thinking 0-199. Also thanks for the tip on the include. I'll take care of that post haste.

bah...sorry AD, I got a double paste in there somehow. I'll get that all fixed and see how it turns out. Again, on my screen the braces are there, I must have jacked it up when I pasted it.

And to think, I have to try and write a bank statement tonight too....waaaaahhhhh...lol. I'll try not to bug you guys too much. Lie to me and tell me I'm not as bad as I have been.

Okay, it all looks nice and neat now, but I'm still getting those errors.

syntax error missing ; before die1 (etc.)
missing type specifier - int assumed.Note C++ and you get the rest. When I click on them it takes me back to the threedice header where the object onedie is used as a data member (onedie die1)

I'll be home in a few min, maybe I'll log back on to a pleasant surprise...hint hint...lol

At least one semicolon seems to be missing ...

int threedice::getsumFaces()
{
         return die1.getroll()+die2.getroll()+die3.getroll() [B];[/B] 
}

Okay, lets try this again. I have three headers as per the prof:
onedie.h, contains the onedie class declaration

threedice.h, contains the threedice class declaration that also uses onedie as datamember

noclass.h, this holds the free function prototypes

onedie.cpp contains the definition of the onedie class and the member functions for onedie

threedice.cpp does the same as onedie and contains the calls to onedie

noclass. cpp is where I have the implementation of the free functions. It's one of these functions I'm having trouble with. When I try to compile it, I get these errors

error C2146: syntax error : missing ';' before identifier 'die1'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'die2'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'die3'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Now I changed the function implementation like vmanes said, but that gave me even more errors, and upon reading the assignment again, this is how he says to do the function. I'm aware that array sizes are defined with constants, I'm just doin what I'm told here, or trying to. Those errors above, when I click on them take me back to the threedice header.

Mit, I caught that too, thank you

Post code. Its impossible for us to evalate the error messages without it.

Okay, I'll post it again, assuming you want it all

If there's a large amount you could just attach the code. Hit the "Go Advance" button, scroll down to load attachments.

one die header:

#ifndef ONEDIE_H
#define ONEDIE_H

class onedie
{
	public:
		void rollit();
		int getroll();

	private:
		int result;
};

#endif

threedice header:

#ifndef THREEDICE_H
#define THREEDICE_H

class threedice
{
	public:
		void rollem();  	  
		int getsumFaces();
		
	private:
		onedie die1;
		onedie die2;
		onedie die3;
};

#endif

noclass header:

#ifndef NOCLASS_H
#define NOCLASS_H

void statistics (int rolls[],int rollsize, int allresults[]);  //prototype given by instructor

//display function here

#endif

onedie.cpp

#include "onedie.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;


void onedie::rollit()
{
	srand(time_t(NULL));
	result= 1 + rand() % 6;
}

int onedie::getroll()
{
	return result;
}

threedice.cpp

#include "threedice.h"
#include <iostream>

using namespace std;

void threedice::rollem()
{
	die1.rollit();
	die2.rollit();
	die3.rollit();
}

int threedice::getsumFaces()
{
	return die1.getroll()+die2.getroll()+die3.getroll();
}

noclass.cpp

#include "noclass.h"
#include "threedice.h"
#include <iostream>

using namespace std;

void statistics (int rolls[], int rollsize,int allresults[])
{
	threedice tryerluck;
	rollsize=200;
	rolls[rollsize];
	allresults[16];

	for(int i=0;i<200;i++)
	{
		tryerluck.rollem();
		rolls[i]= tryerluck.getsumFaces();
	}
}

Okay, that's all of it. Where did I screw up please?

In your THREEDICE.H add the following forward declaration

#define THREEDICE_H
[B]class onedie;[/B]
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    
}

I put the class onedie; in the threedice header and it says undefined class...did I leave something out or have I incorrectly defined it in onedie.cpp?

I was indeed going to call the statistics function in main and there will be more to it. After the for loop, I have to make another one (I think) with a switch to fill the allresults with the spread of results between 3 and 18.

update:
I changed it from class onedie; to #include onedie.h and now it compiles, is that correct?

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

that's what I did...ooo...I almost figured something out on my own...lol.

Okay, now I have to try the loop to fill allresults. I'm thinking a for loop with a switch, does that sound right....or at least like it would work?

Okay, the switch isn't working, I'm getting a bunch of illegal cases. Do I have the wrong condition?

for (int i=0;i<rollsize;i++)
{
        switch (rolls[i])
        case 3:allresults[0] = allresults [0]+1; break;
        case 4:allresults[1] = allresults [1]+1; break;
        case 5:allresults[2] = allresults [2]+1; break;
        case 6:allresults[3] = allresults [3]+1; break;
        case 7:allresults[4] = allresults [4]+1; break;
        case 8:allresults[5] = allresults [5]+1; break;
        case 9:allresults[6] = allresults [6]+1; break;
        case 10:allresults[7] = allresults [7]+1; break;
        case 11:allresults[8] = allresults [8]+1; break;
        case 12:allresults[9] = allresults [9]+1; break;
        case 13:allresults[10] = allresults [10]+1; break;
        case 14:allresults[11] = allresults [11]+1; break;
        case 15:allresults[12] = allresults [12]+1; break;
        case 16:allresults[13] = allresults [13]+1; break;
        case 17:allresults[14] = allresults [14]+1; break;
        case 18:allresults[15] = allresults [15]+1; break;
}

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
}

okay, I feel stupid now

you don't need that switch statement at all

for (int i=0;i<rollsize;i++)
{
        allresults[i] = allresults [i]+1;
}

AD, does that increment the different elements of the results array so you know which numbers are rolled how many times? I used the switch because that's what the prof has in the lesson plan, but I'm just as keen on keeping things simple.

Okay, main looks like it's outputting a memory address instead of a bunch of dice rolls. Should I just move that statistics and display functions to main instead of calling them? Or I might have screwed up the display function....it's supposed to print each element of the allresults array.

Here is main:

#include "threedice.h"
#include "noclass.h"
#include <iostream>

using namespace std;

int main ()
{
	const int rollsize = 200;
    int rolls[rollsize] = {0};
	int allresults[16]={0};


	statistics(rolls,rollsize,allresults);
	displayResults(allresults);


	return 0;
}

The display function

void displayResults(int allresults[])
	{
		cout << allresults << endl;
	}

AD, does that increment the different elements of the results array so you know which numbers are rolled how many times? I used the switch because that's what the prof has in the lesson plan, but I'm just as keen on keeping things simple.

I just looked at that switch statement and saw that it can be greatly simplified. Or something like this:

for (int i=0;i<rollsize;i++)
{
     int index = rolls[i] - 3;
     allresults[index] = allresults [index]+1;
}

I've got the method commented out after my switch, if I can get the display working I'll plug that in and see how it works. I'm pretty sure I messed up the display function, I'm just not sure how yet

Here is main:

#include "threedice.h"
#include "noclass.h"
#include <iostream>

using namespace std;

int main ()
{
	const int rollsize = 200;
    int rolls[rollsize] = {0};
	int allresults[16]={0};


	statistics(rolls,rollsize,allresults);
	displayResults(allresults);


	return 0;
}

The display function

void displayResults(int allresults[])
	{
		cout << allresults << endl;
	}

>>cout << allresults << endl;
That doesn't display the array but only the first element of the array. You need to create a loop and display each element one-at-a-time.

it's going to look an awful lot like the other two loops except with the allresults array isn't it?

0012FBF0
Press any key to continue . . .

that was the result of the code from the last post

it's going to look an awful lot like the other two loops except with the allresults array isn't it?

probably

0012FBF0
Press any key to continue . . .

that was the result of the code from the last post

Ok, so I was wrong -- that is the address of the first element of the array, not its value.

yeah it was...I still have something wrong though, I'm rolling 8 200 times..lol

I'm sorry, that's 9 200 times

void onedie::rollit()
{
	srand(time_t(NULL));
	result= 1 + rand() % 6;
}

Problem might be here -- move that srand() line to be one of the first lines in main() function. It should be executed only once during the lifetime of the program.

that was exactly it, but tell me, how does one come to recognize something like that? I never would have seen that (obviously) in a month o Sundays.

>>but tell me, how does one come to recognize something like that
Experience, practice, practice, and more practice -- thousands of hours of coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.