|
| marknyc (18) | |
| can someone please help with this? | |
| Disch (2130) | |
| I'm at work. I'll check this when I get home. Give me a few hours. | |
| marknyc (18) | |
| Thanks | |
| Disch (2130) | |||||||||
| Okay so the goal here is to step through this code and find out why it's doing what it's doing. Let's start at these loops:
Do you understand what this code is doing? The 'm' for() loop will loop 99 times, each time it will run the 'n' loop which also runs 99 times. In effect, you're running the 'CODE' 99*99 = 9801 times. This has a similar effect as:
The only differences are the values of 'm' and 'n' -- but you're not using either of those in CODE anyway, so that's moot. Ask yourself what behavior it is you're looking for. Once you outline the behavior you can break it up into steps and write the code for each of those steps. 1) You want to generate a random number 2) After a number is generated, you want to print all the generated numbers up to this point (including previous numbers) 3) Then you want to repeat until X condition is met (still unsure when you want this program to exit -- right now it looks like you're just generating thousands of numbers) So the next question is... how do you do each of those steps? Generating a random number is pretty easy... but how about printing all the previously generated numbers? Here's a hint: you'll need to record the numbers somehow. Either in an array or in some other container like I explained in my earlier post. Think about it... if all the numbers were in an array... could you print them? What if you had the following assignment:
Get that function written and working properly. You can test it with simple code to make sure it's working right... like:
Once you have that working, you might have a better idea of how to do the rest of it. | |||||||||
Last edited on | |||||||||
Pages: [1] [2]
This topic is archived - New replies not allowed.
