Horse Race Program help

This is a discussion on Horse Race Program help within the C++ Programming forums, part of the General Programming Boards category; Hello. I'm a high school student (Jr.) taking C++ (I'm pretty new to it). I have to do a horse ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    4

    Horse Race Program help

    Hello. I'm a high school student (Jr.) taking C++ (I'm pretty new to it).

    I have to do a horse race program that's due tonight at 12am.

    I have the horse race portion down pat but I'm very confused with how to show the places of the horses when the race is complete. Any help would be appreciated. Here's the program (the place function is what I made so far to try and display the places of the horses):


    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<lvp\random.h>
    
    void drawtrack()
    {
    clrscr();
    
    cout<<"  ------------------------------------------------------------"<<endl;
    cout<<"1|------------------------------------------------------------|"<<endl;
    cout<<"2|------------------------------------------------------------|"<<endl;
    cout<<"3|------------------------------------------------------------|"<<endl;
    cout<<"4|------------------------------------------------------------|"<<endl;
    cout<<"  ------------------------------------------------------------"<<endl;
    }
    void changehorse(int horsenum, int y)
    {
      gotoxy(y+2,horsenum+1);
      cout<<"-H"<<endl;
    
    }
    
    void movehorse(int horsenum,int &y)
    {
    if(1+random(100)>50 && y<60) {
      changehorse(horsenum,y);
      y++;
    }
    }
    
    void place()
    {
    int p,y,horse1,horse2,horse3,horse4,horsenum;
    
    
    if(horse1=60)
    cout<<"horse 1: 1st place"<<endl;
    else(horse1<60);
    if(horse2=60)
    cout<<"horse 2: 1st place"<<endl;
    else(horse2<60);
    if(horse3=60)
    cout<<"horse 3: 1st place"<<endl;
    else(horse3<60);
    if(horse4=60)
    cout<<"horse 4: 1st place"<<endl;
    else(horse4<60);
    }
    
    void main()
    {
      clrscr();
      randomize();
      drawtrack();
      place();
      int horse1=1;
      int horse2=1;
      int horse3=1;
      int horse4=1;
    
      while(horse1<60||horse2<60||horse3<60||horse4<60)
      {
      movehorse(1,horse1);
      movehorse(2,horse2);
      movehorse(3,horse3);
      movehorse(4,horse4);
      for(long pp=1;pp<=10000000;pp++);
     }
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    In your place function, you have new local variables for all the horses. You should pass the values that you have in main to the place function as arguments and use those instead. Then you will want to use == instead of = to compare. Finally, to find which horse has first place you can compare against 60, but to find which one has second place, you have to find the one that is greater than the others but less than the first place horse. Then for third and fourth you just compare the last two horses. This will probably take a complicated group of ifs and elses.

    One last thing, you will want to call place() near the end of the program, after the horses have completed the race.

  3. #3
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Code:
    void main()
    Ewwww.
    Code:
    int main()
    Code:
    #include<iostream.h>
    Ewwww.
    Code:
    #include <iostream>
    Code:
    #include <conio.h>
    Ewwww. Use something standard.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    for(long pp=1;pp<=10000000;pp++);
    not a good way to wait - eats to much CPU
    search forum for portable sleep implementations... or use nonpotrable/ if you are using other non-portable things anyway
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Array of Structures
    By dmkanz07 in forum C Programming
    Replies: 12
    Last Post: 04-19-2007, 09:55 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21