Computer Science Canada Help with problem that i cant solve! |
Author: | dmitrip [ Thu Mar 01, 2007 7:19 pm ] |
Post subject: | Help with problem that i cant solve! |
i am making a program where i simulate the role of the dice 100 times so thats easy and i got that working but now my next challenge is that i need to put each number under the same number as like an increasing graph so lets say if 1 was rolled 5 times than it will be on top of 1s, and if i got lets say 2 4 times , than 2 will be right beside the 1 4 times so kidna like this: 1 12 12 12 12 any help will be very appreciated here is the code for the dice role [code] var num : int for role : 1..100 randint(num,1,6) put num end for put "123456" [code] thanks alot! |
Author: | HeavenAgain [ Thu Mar 01, 2007 7:35 pm ] | ||
Post subject: | Re: Help with problem that i cant solve! | ||
i wont explain everything on how you do this, (that is your job) but i can say is, you can make an array (if you learned it, or can cehck it out in the f10 help), or make 6 variables for result 1 2 3 4 5 6 and use if; if num=1 then the variable 1 increase if num = 2 then variable 2 increase and so on and for the graph, you dont mean by using graphics command such as drawline? if just puring using char for graph, you can try this compare which is the biggest, and that will be the number of time you will run this loop say if 3 have the most out come then
i hope this helps ![]() |
Author: | PaulButler [ Thu Mar 01, 2007 7:41 pm ] | ||
Post subject: | RE:Help with problem that i cant solve! | ||
I don't know how arrays are used in turing, but you could do something like this:
To count the number of each dice that is rolled. Then you just have to display a bar graph of that data. Btw, the code above is as much turing as I can figure out from reading your post mixed in with some java/c++/pseudocode. Hopefully turing has a close enough equivalent that you can figure out what I did and how it is done in turning. |
Author: | Clayton [ Thu Mar 01, 2007 7:49 pm ] | ||
Post subject: | Re: Help with problem that i cant solve! | ||
This is the same code as above tidied up:
|
Author: | zylum [ Fri Mar 02, 2007 12:36 am ] | ||
Post subject: | RE:Help with problem that i cant solve! | ||
or
|
Author: | Clayton [ Fri Mar 02, 2007 7:45 am ] |
Post subject: | Re: Help with problem that i cant solve! |
bah dammit! Ah well, I was just trying to show him with the case because chances are he better understands it (and, admittedly, I didn't even think about what you did zylum, even though I do it 99% of the time ![]() My advice is: If you understand zylum's code, use it, if not, you could always compress my code down into a for loop, an if, and a variable. |