I have been assigned the following question. Write a program that generates 10000 random integers in the range 0-99 and produces a Histogram from the random data. Assume that we wish to count the number of numbers that lie in each of the intervals 0-9, 10-19, 20-29, ........., 90- 99. This requires that we hold 10 counts, use an array to hold the 10 counts. While it would be possible to check which range a value x lies in by using if-else statements this would be pretty tedious. A much better way is to note that the value of x/10 returns the index of the count array element to increment. I have the following code but I keep getting subscript requires array or pointer type error.
#include<iostream>
using namespace std;
int main() {
int count[10], i, nums[10000];
// Create the Samples
for (i = 0; i < 10000; i++){
nums[i] = rand() % 100;
//Actually displaying the histogram.
cout << "0-9: ";
for (i = 0; i < nums[0][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "10-19: ";
for (i = 0; i < nums[1][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "20-29: ";
for (i = 0; i < nums[2][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "30-39: ";
for (i = 0; i < nums[3][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "40-49: ";
for (i = 0; i < nums[4][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "50-59: ";
for (i = 0; i < nums[5][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "60-69: ";
for (i = 0; i < nums[6][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "70-79: ";
for (i = 0; i < nums[7][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "80-89: ";
for (i = 0; i < nums[8][1] / 20; i++) { cout << "X"; }
cout << endl;
cout << "90-99: ";
for (i = 0; i < nums[9][1] / 20; i++) { cout << "X"; }
cout << endl;
}
}