fork download
  1. #include <stdio.h>
  2.  
  3. #define RACES 10 //10 races daily
  4. #define MAX_HORSES 20 // Each race could have up to a max of 20 horses, each uniquely identified by the numbers 1 through 20
  5. //Betting amount limit per race:  minimum of $5 to a maximum of $1000
  6. #define BET_MIN 5;
  7. #define BET_MAX 1000;
  8. #define GAINAMT_MUL_WIN 10; //*How much bet will be multiplied by if correctly guess a win
  9. #define GAINAMT_MUL_PLACE 5; //*How much bet will be multiplied by if correctly guess a horse that places
  10. #define GAINAMT_MUL_SHOW 3; //*How much bet will be multiplied by if correctly guess a horse that shows
  11.  
  12. //**************************************************************
  13. // Function: myHorseBet
  14. //
  15. // Purpose: calculate winnings associated with horse bet
  16. //
  17. // Parameters:
  18. // myBet : structure that has information on the bet that I placed
  19. // theDailyResults: structure that has information on the daily race results
  20. //
  21. //
  22. // Returns: float with winnings associated with the bet
  23. //
  24. //**************************************************************
  25.  
  26. // race results
  27. struct raceResult
  28. {
  29. int raceNumber; // The unique Race Number
  30. int winningHorseNumber; // 1st place horse number for the race
  31. int placeHorseNumber; // 2nd place horse number for the race
  32. int showHorseNumber; // 3rd place horse number for the race
  33. };
  34.  
  35.  
  36. // assume you can access this array that contains the results of horse races for a given day
  37. struct raceResult theDailyResults[RACES];
  38.  
  39. // your specific race wager
  40. struct raceWager
  41. {
  42. int raceNumber; // the race number where you bet your horse
  43. int myHorseNumber; // the horse you bet on
  44. float myBetAmount; // how much money you are betting
  45. char betType; // W for "Win", P for "Place", or S for "Show"
  46. };
  47.  
  48. // call this function and pass in your bet to see how much you won ... if you lost or there
  49. // is an error  in your wager info, it just returns zero
  50. float myHorseBet (struct raceWager myBet, struct raceResult raceResult1){ /*Eventually, second argument will need to be array*/
  51. int winnings=0; //declaring and initializing integer variable for winnings
  52. if (myBet.raceNumber== raceResult1.raceNumber){ //checking if the race number associated with the bet is equal to the race number that have results for
  53. // if placed bet expecting the horse that bet on to win
  54. if (myBet.betType='W'){
  55. if (myBet.myHorseNumber==raceResult1.winningHorseNumber){// check if horse that expected to win actually did win
  56. winnings=myBet.myBetAmount*GAINAMT_MUL_WIN;
  57. }
  58. }
  59. // if placed bet expecting the horse that bet on to place
  60. else if (myBet.betType='P'){
  61. if (myBet.myHorseNumber==raceResult1.placeHorseNumber ||myBet.myHorseNumber==raceResult1.winningHorseNumber){// check if horse that expected to place actually did place
  62. winnings=myBet.myBetAmount*GAINAMT_MUL_PLACE;
  63. }
  64. }
  65. // if placed bet expecting the horse that bet on to show
  66. else if (myBet.betType='S'){
  67. if (myBet.myHorseNumber==raceResult1.showHorseNumber || myBet.myHorseNumber==raceResult1.placeHorseNumber ||myBet.myHorseNumber==raceResult1.winningHorseNumber){// check if horse that expected to show actually did show
  68. winnings=myBet.myBetAmount*GAINAMT_MUL_SHOW;
  69. }
  70. }
  71. }
  72. return winnings;
  73.  
  74. }
  75.  
  76. int main() {
  77. struct raceWager raceWager1={1,1,5,'S'}; // bet on race 1, bet on horse 1, bet $5, bet on horse 1 placing
  78. struct raceResult raceResult1={1,1,2,3}; //race 1, horse 1 won, horse 2 second, horse 3 third
  79. int winnings=myHorseBet(raceWager1,raceResult1);
  80.  
  81. printf("Winnings: %i\n", winnings);
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Winnings: 50