simple stat example wont compile

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
43
44
45
46
47
48
// stats.cpp
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int rand_0toN1(int n);
int hits[10];

int main()
{
	int n; // Number of trials; prompt from user
	int i; // All-purpose loop variable
	int r; // Holds a random value

	srand(time(NULL));	// Set seed for randomizing.

	cout << "Enter how many trials and press ENTER: ";
	cin >> n;

	// Run n trials. For each trial, get a num 0 to 9 and then
	// increment the corresponding element in the hits array.

	for (i = 0; i < n; i++)
	{
		r = rand_0toN1(10);
		hits[r]++;
	}
	
	// Print all elemtents in the hits array, along with ratio of
	// hits (n / 10).

	for (i = 0; i < 10; i++)
	{
		cout << i << ": " << hits[i] << " Accuracy: ";
		double results = hits[i];
		cout << results / (n/10) << endl;
	}
	return 0;
}

// Random 0-to-N1 Function.
// Generate a random integer from 0 to N-1.

int rand_0toN1(int n)
{
	return rand() % n;
}


got this straight out of the book (c++ without fear second edition)
and im using ubuntu
Add #include <cstdlib>

It is required for some stuff in thatcode.
thx ((=
Topic archived. No new replies allowed.