Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with problem that i cant solve!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dmitrip




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: 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
code:
for i:1.. variable 3
   for a:1..the second biggest
     for b: 1.. the 3rd
       for c:1.. the 4th
         for d: 1..the 5th
           for e:1..the smallest
              put "1  2  3  4  5  6*the smallest*"
          end for
           put "1*the 5th*  2  3  4  5 "
          end for
          put "  2*the 4th*  3 4 5"
and so on...

i hope this helps Wink
PaulButler




PostPosted: 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:

Turing:

var c1 : int
var c2 : int
var c3 : int
var c4 : int
var c5 : int
var c6 : int

var r : int

for roll : 1..100

r = randint(r,1,6)

if(r == 1){
c1 = c1 + 1
}
else if(r == 2){
c2 = c2 + 1
}

end for


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.
Clayton




PostPosted: 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:

Turing:

var d : array 1 .. 6 of int := init (0, 0, 0, 0, 0, 0)

case Rand.Int (1, 6) of
    label 1 :
        d (1) += 1
    label 2 :
        d (2) += 1
    label 3 :
        d (3) += 1
    label 4 :
        d (4) += 1
    label 5 :
        d (5) += 1
    label 6 :
        d (6) += 1
end case
zylum




PostPosted: Fri Mar 02, 2007 12:36 am   Post subject: RE:Help with problem that i cant solve!

or
code:
var d : array 1 .. 6 of int := init (0, 0, 0, 0, 0, 0)
d(Rand.Int(1, 6)) += 1
Clayton




PostPosted: 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 Embarassed)

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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: