Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Randomly select an equation expression (Turing)
Author Message
snozking

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

scholarlytutor

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: