fork download
  1. // Assignment Final Question 6
  2. //
  3. // Name: <Maribel Fuentes>
  4. //
  5. // Class: C Programming, <Fall 2024>
  6. //
  7. // Date: <December 2, 2024>
  8.  
  9. #include <stdio.h>
  10.  
  11. #define RACES 10
  12.  
  13. // Race results structure
  14. struct raceResult {
  15. int raceNumber; // The unique Race Number
  16. int winningHorseNumber; // 1st place horse number for the race
  17. int placeHorseNumber; // 2nd place horse number for the race
  18. int showHorseNumber; // 3rd place horse number for the race
  19. };
  20.  
  21. // Assume you can access this array that contains the results of horse races for a given day
  22. struct raceResult theDailyResults[RACES];
  23.  
  24. // Your specific race wager structure
  25. struct raceWager {
  26. int raceNumber; // The race number where you bet your horse
  27. int myHorseNumber; // The horse you bet on
  28. float myBetAmount; // How much money you are betting
  29. char betType; // W for "Win", P for "Place", or S for "Show"
  30. };
  31.  
  32. // Function to calculate the winnings based on the bet
  33. float myHorseBet(struct raceWager myBet, struct raceResult theDailyResults[]) {
  34. for (int i = 0; i < RACES; i++) {
  35. if (theDailyResults[i].raceNumber == myBet.raceNumber) {
  36. switch (myBet.betType) {
  37. case 'W': // Win
  38. if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber) {
  39. return myBet.myBetAmount * 2;
  40. }
  41. break;
  42. case 'P': // Place
  43. if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber ||
  44. theDailyResults[i].placeHorseNumber == myBet.myHorseNumber) {
  45. return myBet.myBetAmount * 1.5;
  46. }
  47. break;
  48. case 'S': // Show
  49. if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber ||
  50. theDailyResults[i].placeHorseNumber == myBet.myHorseNumber ||
  51. theDailyResults[i].showHorseNumber == myBet.myHorseNumber) {
  52. return myBet.myBetAmount * 1.2;
  53. }
  54. break;
  55. default:
  56. return 0; // Invalid bet type
  57. }
  58. }
  59. }
  60. return 0; // Race number not found or horse did not place
  61. }
  62.  
  63. int main() {
  64. // Example usage
  65. struct raceResult theDailyResults[RACES] = {
  66. {1, 5, 3, 8},
  67. {2, 2, 4, 1},
  68. {3, 7, 6, 5},
  69. {4, 1, 3, 2},
  70. {5, 4, 5, 6},
  71. {6, 8, 7, 3},
  72. {7, 6, 2, 4},
  73. {8, 3, 1, 7},
  74. {9, 5, 8, 2},
  75. {10, 7, 6, 1}
  76. };
  77.  
  78. struct raceWager myBet = {3, 7, 100.0, 'W'};
  79. float winnings = myHorseBet(myBet, theDailyResults);
  80.  
  81. printf("You won $%.2f\n", winnings);
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
You won $200.00