help!!!!!!!!!!

this is what code i have an this is what i need...Write a program that simulates the tossing of 3 die and computes the probability of obtaining each of the values 3 to 18. Your program should ask the user how many rolls to simulate, and then perform the simulation and report the results. Include an appropriate srand() function so you get different results each time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include "stdafx.h"
#include <iostream>
using namespace std;
#include <cstdlib>
#include <ctime>
#include <iomanip>

int pairofdiceroll();
int main()

//int _tmain(int argc, _TCHAR* argv[])
{
	int rollarray[18]={0};
	int numrolls;
	int i;
	srand(static_cast<unsigned>(time(NULL)));
	cout << " How many roll?";
	cin >> numrolls;
	for (i=0; i<numrolls; i++)
	{
		int theRoll;
		theRoll= pairofdiceroll();
		cout << theRoll << " ";
		rollarray[ theRoll]++;
	}
	cout << "\nResults\n";
	for(i=0; i<11; i++)
	{
		cout << showpoint << fixed << setprecision(2);
		cout << setw(10) << rollarray[i] << " " << setw(2) << i+3<< "'s were rolled(" << (static_cast<double>(rollarray[i])/numrolls)*100 << "%)\n";
	}
	return 0;
}
int pairofdiceroll()
{
	int result;
		int d1 = rand()%6+1;
		int d2 = rand()%6+1;
		int d3 = rand()%6+1;
		result = d1+d2+d3;
		return result;
}
In order to hold numbers from 0 (the index an array starts at) to 18, an array should have 19 elements.

If you're recording the actual numbers rolled from 3 to 18, you don't need to make adjustments when you're displaying the results (and what gives you the idea that 18-3 is 11?)

In short, line 13 should be: int rollarray[19] = {0};
line 27 should be: for (unsigned i=3; i<19; ++i )
and on line 30 you should replace i+3 with i.

Three die are not a pair.

"Here is my code. I'm not going to tell you what it actually does, but this is what is required" is not a good way to ask questions. "Help!!!!!!!!" is a very, very crappy subject, which is specifically warned against in the sticky at the top of this very forum (that you were apparently too lazy to read.)
Last edited on
Topic archived. No new replies allowed.