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

Username:   Password: 
 RegisterRegister   
 counted loop and random number [help]
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ella




PostPosted: Mon Oct 12, 2009 7:13 pm   Post subject: counted loop and random number [help]

What is it you are trying to achieve?
to determine how many values of seven was created in random numbers from 1 to 20.


What is the problem you are having?
maybe something wrong with my codes and/or i'm missing some codes.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
this is what i got so far:

Turing:


var numbers, sevens : int
%
put "Random numbers: "
%
for i : 1 .. 100
    randint (numbers, 1, 20)
    put numbers : 8 ..
end for
%
if numbers = 7 then
sevens:= sevens + 1
put "Sevens: ", sevens
else put "No sevens."
end if



Please specify what version of Turing you are using
Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Oct 12, 2009 7:44 pm   Post subject: RE:counted loop and random number [help]

code:

if numbers = 7 then
    sevens:= sevens + 1
    put "Sevens: ", sevens
else
    put "No sevens."
end if

This needs to be inside the for loop
Tony




PostPosted: Mon Oct 12, 2009 7:46 pm   Post subject: RE:counted loop and random number [help]

You probably want to check if the random number was 7 more than just once.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zren




PostPosted: Mon Oct 12, 2009 7:51 pm   Post subject: Re: counted loop and random number [help]

Also don't forget to initialize the variable sevens. aka set it to zero in the beginning.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: