1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++ Help

Discussion in 'Software Development' started by Rhino24, Apr 15, 2008.

Thread Status:
Not open for further replies.
  1. Rhino24

    Rhino24 Thread Starter

    Joined:
    Feb 8, 2008
    Messages:
    41
    I wrote this code to re-create the classic race of the tortoise and the hare and everything compiles fine. Just the logic is messed up. When I run the program all I see is BANG AND THEY'RE OFF and who wins. I should be seeing a T for the Tortoise and and H for the Hare going across the screen. Can anyone tell me what I am doing wrong.

    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    using namespace std;

    int random_1();

    int main()

    {

    int i = 0;

    int j = 0;

    int check;

    int check_1;

    char play_again = '\n' ;



    int tortoise[70];

    int hare[70];



    cout << "BANG !!!!!\n"
    "AND THEY'RE OFF !!!!!" << endl;



    while(play_again == '\n')

    {

    while(i <= 69 && j <= 69)

    {

    tortoise = 0;;

    check = random_1();


    if(check == 1 || check == 2 || check == 3 || check == 4 || check ==
    5)

    tortoise[i+=3] = 0;



    if(check == 6 || check == 7)

    tortoise[i-=6] = 0;



    if(check == 8 || check == 9 || check == 10)

    tortoise[i+=1] = 0;



    char *ptr;

    char line[71] = "----------------------------------------------------------------------";



    ptr = line;



    if(i < 0){

    i = 0;

    *(ptr + i) = 'T';}



    *(ptr + i) = 'T';



    hare[j] = 0;

    check_1 = random_1();



    if(check_1 == 1 || check_1 == 2)

    hare[j] = 0;



    if(check_1 == 3 || check_1 == 4)

    hare[j+=9] = 0;



    if(check_1 == 5)

    hare[j+=12] = 0;



    if(check_1 == 6 || check_1 == 7 || check_1 == 8)

    hare[j++] = 0;



    if(check_1 == 9 || check_1 == 10)

    hare[j-=2] = 0;



    if(j < 0){

    j = 0;

    *(ptr + j) = 'H';}



    *(ptr + j) = 'H';



    if(i == j){

    *(ptr + i) = 'O';

    *(ptr + i + 1) = 'U';

    *(ptr + i + 2) = 'C';

    *(ptr + i + 3) = 'H';}


    break;

    }


    if(i >= 69)

    {

    cout << "TORTOISE WINS!!! YAY!!!\n" << endl;

    break;

    }

    if(j >= 69)

    {

    cout <<"HARE WINS. YUCH.\n" << endl;

    break;

    }

    if(j >= 69 && i >= 69)

    {

    cout << "IT'S A TIE\n";

    break;

    }



    }

    return 0;


    }

    int random_1()

    {

    srand(time(NULL));

    return (1 + rand() % 10);

    }
     
  2. tritonfx

    tritonfx

    Joined:
    Jan 20, 2008
    Messages:
    28
    I might be mistakened but you didn't actually print out "line"
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/704170

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice