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

Username:   Password: 
 RegisterRegister   
 Randomly select an equation expression (Turing)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
snozking




PostPosted: Tue Mar 22, 2022 10:36 am   Post subject: Randomly select an equation expression (Turing)

i want to write a code to randomly select from * / + and -.

how can i do that in turing?

thankyou Canada
Sponsor
Sponsor
Sponsor
sponsor
scholarlytutor




PostPosted: Tue Mar 22, 2022 4:08 pm   Post subject: RE:Randomly select an equation expression (Turing)

Hi snozking,

So first you'll need two variables to store your left and right numbers. You also need one more integer variable to store your random number (call it RandomNumber)

Then, there's a procedure called randint. It works like this:

randint(RandomNumber, 1, 4)

Your variable now has a random number inside of it between 1 and 4.

Finally, you need an if block to check which number you got. It will work something like this:

if RandomNumber = 1 then
put LeftNumber, " + ", RightNumber
elsif RandomNumber = 2 then...

and I'll let you try to figure out the rest.

Hope that helps. Feel free to post your code here if you're still having trouble.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: