Is that what you meant?
You're right. I needed to initialize the array from outside the main function. ThanksCode:#include <iostream> #include <ctime> #include <cmath> #include <stdlib.h> using namespace std; int rand_0toN1(int n); int hits[0]; int main() { for (;;) { int n, i, r, max; srand(time(NULL)); cout << "The highest number to be generated: "; cin >> max; cout << "Enter how many trials: "; cin >> n; for (i = 0; i < n; i++) { r = rand_0toN1(max); hits[r]++; } for (i = 0; i < max; i++) { cout << i << ": " << hits[i] << " Accuracy: "; double results = hits[i]; cout << results / (n / max) << endl; } } return 0; } int rand_0toN1(int n) { return rand() % n; }




Reply With Quote