here is the header and the main
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
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. \n" ; for(x=0 ; x<NUMBEROFHORSES ; x++) //loop asign and display odds { odds[x]= assignOdds(x) ; cout << "Horse " << x+1 << " Odds are " << odds[x] <<"/1 \n" ; } 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 -\n "; 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; }
int *ptr;
ptr = new int;
*ptr = 100;
Would this work?

