Write a program that generates 100 random integers between 0 and 9 and displays the count for each number.
Hints:
Use rand() % 10 to generate random numbers from 0 … 9, and create an array to store the count of each number.
Create an array[100],using a loop fill the array with 100 random numbers from 0 to 9 rand() % 10.
Create another counter array with a size of 10 to capture the counts of each number
Use a for-loop to go through the array and increment the values of the array corresponding to the random values. (i.e. if the random number is 9, you should do counter[9]++, where counter[0] stores the count for zero, counter[1] stores the count for 1, etc.
#include<cstdlib>
using std::rand;//The random function
using std::srand;//the initializes the rand generator
#include<ctime>
using std::time;//used to seed the generator to generate rand number
int main()
{
/*
*create an array to store the numbers generated
*create array for the number occurrence
*seed the generator
*for(int i = 0***********)
*{
*
*Hints:
*Use rand() % 10 to generate random numbers from 0 … 9,
*}
*for(int i*********)
*if the random number is 9, you should do counter[9]++
*/
return 0;
}
The program that Sanction is showing you, does only create numbers 0 to 9, and fills an array that can hold 100 numbers. Line 17 just prints out the array number, then shows what value is in array[i].
Lines 9 to 12, fills the 100 count array, with the numbers 0 to 9.
Just create another array that holds 10 numbers. (ie int holder[10]. When you run the j for loop, check what array[j] holds. If it's a 5, increase the count of holder[5] by 1.
as in..
@whitenite1 That's pretty much it! now ive been trying to toy with your code to make the number of times it keeps track of the numbers 0-9 equel up to 100. So it should say the" number 0 was chosen 25 times" and so on. if that's not a good explanation than the best way I can describe it is 100 random numbers should be generated and split up evenly between 0-9.