Click here to Skip to main content
15,998,673 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello to all,

I have an exercise for my school and I have no idea how to solve it, can you please help me? :doh:

Exercise:

Write a program that randomly generates 100 integer values in the range 1 to 50. Your program should display how many numbers of the numbers generated occurred in the range 1..10, 11.. 20, etc.
For example, your program might display:

1..10  20
11..20 25
21..30 12
31..40 23
41..50 20


Thank you very much!
Posted
Updated 2-Jan-11 10:40am
v2

1 solution

Without giving you the answer directly, otherwise i would be doing YOUR homework, and you have never heard of google or read your course notes;

1) use the RANDOM class
2) create an array to store the 5 categories
3) check the returned random number against the category limits and increment the value stored in the relevant array index
4) display the output
5) repeat as required
 
Share this answer
 
Comments
Manfred Rudolf Bihy 2-Jan-11 16:45pm    
My answer would have run along these lines, so I refrain. Have my 5!
Kasson 3-Jan-11 0:50am    
Good Clue. My 5 too.
Shani Natav 3-Jan-11 3:54am    
I'm tempted to give him an overly complicated solution....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900