Here's what i haD to do ?

1) Write a program which simulates the rolling of pair of 6-sided dice and computes the % occurrence of
a specific dice roll value ranging from 2-12.

2) modify the dice class to keep track of the number of times a die has been rolled, Add a private state
variable called myRollCount and add a new member function called numrolls() which returns the times
the die has been rolled since it was instantiated. After computing the % occurrence of a dice roll, print
out number of times rolled.

results should be example:

2 <<<<<35/1000 <<<<<3.5%

3<<<<< 51/1000<<<<< 5.1%

till 12

Here is my codes

#include <iostream>
#include <E:\dicetry2\dicetry2\dice2.h>
using namespace std;

int main()
{
dice die1(6), die2(6);
int loop = 0;
int counter = 2;
int sum = 0;
double percent = 0;
double solve = 0;

while (counter <= 12)
{
for(loop=1; loop <=1000; loop++)
{
sum = die1.roll() + die2.roll();

die1.rollings();

die2.rollings();

if (sum==counter){

percent++; } }

solve= percent/10;

cout<<counter <<"\t"<<percent<<"/1000\t"<<(percent/10)…

counter++;

percent = 0;}

cout<< die1.numrolls() << "\tFor die number 1" <<endl;

cout<< die2.numrolls() << "\tFor die number 2"<<endl;

system("pause");
return(0);
}

HERE IS my .h file

#ifndef DICE_H
#define DICE_H

#include<stdlib.h>
#include<time.h>

class dice{
public:

dice(int sides);

int roll();

int numrolls();

int numSides();

int rollings();

private:
int myRollCount;
int mySides;
};

dice::dice (int sides)

{
srand(unsigned(time(0)));
mySides = sides;
myRollCount = 0;
}

int dice::roll()
{
return (rand () %mySides)+1;// creates number between 1 and 6

}
int dice::rollings()
{
myRollCount++;
return myRollCount;
}

int dice::numrolls()
{
return myRollCount;
}

int dice::numSides()

{
return mySides;
}

#endif

i got my results my output IS GOOD. EVERYTHING IS RUNNING.

The thing is i received lots of help doing this i do not know how everything works down to the basics, and i have to present this. Can someone explain this to me in detail , explaining how things work, how the code communicate . how this whole program functions. please so my maybe i can figure it out when i present.
Topic archived. No new replies allowed.