Basically I did some code for betting on horses here
here the header with the function prototypes
Code:
int assignOdds (int horse) ; // function to assign odds
int whichHorseToBetOn (void) ; // function to ask which horse to bet on
int getAmount (void) ; // function to ask how much to bet
int runRace (void) ; // function to run the race
Main file
Code:
//Horse Betting
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "betting.h"
using namespace std ;
int Cash = 100; // starting cash
int const NUMBEROFHORSES = 8 ;
int Bet = 0 ; // how much have they bet
int horseWon = 0 ;
int x =0 ;
int odds[7] ; // array which holds each horses odds
int tempOdds = 0 ;
int winner = 0;
int thisBet = 0; // holds horse bet on
int Amount = 0; //. holds amount bet this race
int main()
{
while (Cash > 0)
{
cout << "You have " << Cash << " to spend. " ;
for(x=0 ; x<NUMBEROFHORSES ; x++) //loop asign and display odds
{
odds[x]= assignOdds(x) ;
cout << "Horse " << x+1 << " Odds are " << odds[x] <<"/1 " ;
}
cout << "Which Horse do you want to bet on - " ;
Bet = whichHorseToBetOn() ;
thisBet=getAmount();
cout << endl ;
winner=runRace();// selects winning horse randomly with runRace() function
if (winner+1 == Bet) {
Cash = Cash+(thisBet*odds[winner])+thisBet ; // If you have picked the winner then calculate earnings
}
}
}
int assignOdds (int horse) // assign random odds to horse
{
tempOdds=(rand()%10)+1;
return tempOdds ;
}
int whichHorseToBetOn ()
{
cin >> Bet ;
return Bet ;
}
int getAmount ()
{
cout << "How much do you want to bet?
You currently have " << Cash << " to spend - ";
cin >> Amount ;
Cash=Cash-Amount ;
return Amount ;
}
int runRace () // calculates randomnly which horse has won the race and displays it on screen
{
horseWon=(rand()%8);
cout << "Horse " << horseWon+1 << " has won the race!
" ;
cout << endl << endl << endl ;
return horseWon;
}
Now its a fairly simple program but what I want to do now is to do it with class's
So i'm writing this off the top of my head
race.h file
Code:
class race:
{
public:
race();
virtual ~race();
int assignodds(int horse);
int whichhorsetobeton(void);
int getAmount(void);
int RunRace(void);
private:
}
then my race.cpp would be
Code:
race::race
{
}
race::~race()
{
}
int race::assignOdds(int horse)
{
tempOdds=(rand()%10)+1;
return tempodds;
}
int race::getAmount()
{
cout << "How much do you want to bet?
You currently have " << Cash << " to spend - ";
cin >> Amount ;
Cash=Cash-Amount ;
return Amount ;
}
int race::whichhorsetobeton()
{
cin >> Bet ;
return Bet ;
}
int race::runRace()
{
horseWon=(rand()%8);
cout << "Horse " << horseWon+1 << " has won the race! " ;
cout << endl << endl << endl ;
return horseWon;
}
Haven't time to write a main.cpp to call all that in,so is any of it right?
I'm pretty sure the race.cpp is wrong,I think I have to put in setters and getters in there but I'm pretty iffy on those