Results 1 to 3 of 3

Thread: a friend gave this to me

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145

    a friend gave this to me

    He thinks that I can program and I really stink at it.

    Can soembody please do this so he will get off my back?

    please!
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145
    here is the second part.....
    Attached Images Attached Images  
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, they basically told you everything you need to know already.

    Have a variable "hare" and one "tortoise", they save the positions. Have a while(true) loop. This is the running loop. Before you enter it, print:
    cout << "BANG !!!!!\nAND THEY'RE OFF !!!!!" << endl;

    In the loop you get a random number (rand() from stdlib.h)(use the modulo % operator to limit the range). Don't forget to init the random number generator with srand, usually by feeding it with the output of time(NULL) or GetTickCount().
    Use the number to determine what the hare does, adjust it's position. Then get a second random number and use it to determine what the tortoise does. Then evaluate the results (tortoise bites rabbit, wins, loses, tie, nothing). When the race shall end, use the break statement.
    The last part of the loop should be some delay, you can use the WinAPI Sleep(milliseconds) for this. I recommend 950 milliseconds delay.
    The printing itself should be easy. Determine the lower of the two positions. Use setw (iomanip.h) to position the cursor at this pos. Print the character of the current animal (or OUCH!). The feed setw a number determined by this:
    cout << setw( larger - smaller - 1) << letterOfAnimal;
    The complete statement would therefore be
    cout << setw(smaller);
    if(smaller == larger)
    cout << "OUCH!" << endl;
    else
    cout << letterOfSlowAnimal << setw(larger - smaller - 1) <<
    letterOfFastAnimal;

    This will print the track. Then go for another round.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width