Thread: Program related in using RANDOM numbers using C.

  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Cebu City, Philippines
    Posts
    1

    Program related in using RANDOM numbers using C.

    I have an assignment and its quite difficult to me to make because im still a beginner and I badly need this before 12 midnight.
    My assignment goes like this:

    The tortoise and the hare, in this project you will recreate one of the truly great moments in history, namely the classic race of the tortoise and the hare.
    Our contenders begin the race at “square 1” of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.

    The two animals take turns in moving positions. Your program should randomly adjust the position of the animals according to the following rules:



    Animal Move type Random No. Actual move
    Tortoise Fast plod 1-5 3 squares to the right
    Slip 6-7 6 squares to the left
    Slow plod 8-10 1 square to the right
    Hare Sleep 1-2 No move at all
    Big hop 3-4 9 squares to the right
    Big slip 5 12 squares to the left
    Small hop 6-8 1 square to the right
    Small slip 9-10 2 squares to the left




    Keep track of the positions of the animals (values from 1 to 70). Start each animal at position 1 (i.e. the “starting gate”). If an animal slips below position 1, move the animal back to position 1. Generate a random integer i in the range 1 to 10. For the tortoise, perform a “fast plod” when i is between 1 and 5, a slip when 6 to 7 or a slow plod when 8 to 10. Use the same technique to move the hare.
    Begin the race by printing “Bang!! And they’re off!!”. For each turn, update the race track. Occasionally the contenders will land on the same square. In this case, the tortoise bites the hare and your program should print “Ouch” beginning at that position. Test if either animal has reached or passed square 70. If so, then print the winner and end the program.


    I already made a program but it doesn't repeat. Please help me.

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    25
    If your program is not looping through the turns, then your problem is likely to be with control flow: do/while, for, if/then. Look at your overall plan for the program. There should probably be some type of loop that inspects whether or not a player has reached the goal. Nested inside that might be a loop counting the succession of turns.

    If your computer class is structured well, then there are probably examples in the lessons of the textbook and class which should get you to an 80% solution. A lot of times homework will involve simple modifications to existing examples so that the student can show they can apply the concepts. The parts needed to build your answer should be in the past few chapters.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Ashleykaye View Post
    I already made a program but it doesn't repeat. Please help me.
    Nobody with a lick of sense is going to try to diagnose your problem without seeing your source code...

    Posting code

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Take a look at the following:
    Once you are done reading through those lessons you should be able to complete this assignment without any problems.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random numbers not random?
    By yacek in forum C Programming
    Replies: 6
    Last Post: 10-08-2010, 06:57 PM
  2. Please help me on my simple program PSEUDO RANDOM NUMBERS
    By metaljacob in forum C Programming
    Replies: 21
    Last Post: 09-16-2010, 08:31 AM
  3. Replies: 4
    Last Post: 11-16-2004, 07:29 AM
  4. Replies: 2
    Last Post: 12-25-2003, 01:31 AM
  5. Random numbers works in one program, not in another
    By Shadow12345 in forum C++ Programming
    Replies: 27
    Last Post: 09-30-2002, 04:06 PM