// Assignment Final Question 6
//
// Name: <Maribel Fuentes>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 2, 2024>
#include <stdio.h>
#define RACES 10
// Race results structure
struct raceResult {
int raceNumber; // The unique Race Number
int winningHorseNumber; // 1st place horse number for the race
int placeHorseNumber; // 2nd place horse number for the race
int showHorseNumber; // 3rd place horse number for the race
};
// Assume you can access this array that contains the results of horse races for a given day
struct raceResult theDailyResults[RACES];
// Your specific race wager structure
struct raceWager {
int raceNumber; // The race number where you bet your horse
int myHorseNumber; // The horse you bet on
float myBetAmount; // How much money you are betting
char betType; // W for "Win", P for "Place", or S for "Show"
};
// Function to calculate the winnings based on the bet
float myHorseBet(struct raceWager myBet, struct raceResult theDailyResults[]) {
for (int i = 0; i < RACES; i++) {
if (theDailyResults[i].raceNumber == myBet.raceNumber) {
switch (myBet.betType) {
case 'W': // Win
if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber) {
return myBet.myBetAmount * 2;
}
break;
case 'P': // Place
if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber ||
theDailyResults[i].placeHorseNumber == myBet.myHorseNumber) {
return myBet.myBetAmount * 1.5;
}
break;
case 'S': // Show
if (theDailyResults[i].winningHorseNumber == myBet.myHorseNumber ||
theDailyResults[i].placeHorseNumber == myBet.myHorseNumber ||
theDailyResults[i].showHorseNumber == myBet.myHorseNumber) {
return myBet.myBetAmount * 1.2;
}
break;
default:
return 0; // Invalid bet type
}
}
}
return 0; // Race number not found or horse did not place
}
int main() {
// Example usage
struct raceResult theDailyResults[RACES] = {
{1, 5, 3, 8},
{2, 2, 4, 1},
{3, 7, 6, 5},
{4, 1, 3, 2},
{5, 4, 5, 6},
{6, 8, 7, 3},
{7, 6, 2, 4},
{8, 3, 1, 7},
{9, 5, 8, 2},
{10, 7, 6, 1}
};
struct raceWager myBet = {3, 7, 100.0, 'W'};
float winnings = myHorseBet(myBet, theDailyResults);
printf("You won $%.2f\n", winnings);
return 0;
}
Ly8gQXNzaWdubWVud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AgIC8vIEhvdyBtdWNoIG1vbmV5IHlvdSBhcmUgYmV0dGluZwogICAgY2hhciBiZXRUeXBlOyAgICAgICAgLy8gVyBmb3IgIldpbiIsIFAgZm9yICJQbGFjZSIsIG9yIFMgZm9yICJTaG93Igp9OwoKLy8gRnVuY3Rpb24gdG8gY2FsY3VsYXRlIHRoZSB3aW5uaW5ncyBiYXNlZCBvbiB0aGUgYmV0CmZsb2F0IG15SG9yc2VCZXQoc3RydWN0IHJhY2VXYWdlciBteUJldCwgc3RydWN0IHJhY2VSZXN1bHQgdGhlRGFpbHlSZXN1bHRzW10pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgUkFDRVM7IGkrKykgewogICAgICAgIGlmICh0aGVEYWlseVJlc3VsdHNbaV0ucmFjZU51bWJlciA9PSBteUJldC5yYWNlTnVtYmVyKSB7CiAgICAgICAgICAgIHN3aXRjaCAobXlCZXQuYmV0VHlwZSkgewogICAgICAgICAgICAgICAgY2FzZSAnVyc6IC8vIFdpbgogICAgICAgICAgICAgICAgICAgIGlmICh0aGVEYWlseVJlc3VsdHNbaV0ud2lubmluZ0hvcnNlTnVtYmVyID09IG15QmV0Lm15SG9yc2VOdW1iZXIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG15QmV0Lm15QmV0QW1vdW50ICogMjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICdQJzogLy8gUGxhY2UKICAgICAgICAgICAgICAgICAgICBpZiAodGhlRGFpbHlSZXN1bHRzW2ldLndpbm5pbmdIb3JzZU51bWJlciA9PSBteUJldC5teUhvcnNlTnVtYmVyIHx8CiAgICAgICAgICAgICAgICAgICAgICAgIHRoZURhaWx5UmVzdWx0c1tpXS5wbGFjZUhvcnNlTnVtYmVyID09IG15QmV0Lm15SG9yc2VOdW1iZXIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG15QmV0Lm15QmV0QW1vdW50ICogMS41OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgJ1MnOiAvLyBTaG93CiAgICAgICAgICAgICAgICAgICAgaWYgKHRoZURhaWx5UmVzdWx0c1tpXS53aW5uaW5nSG9yc2VOdW1iZXIgPT0gbXlCZXQubXlIb3JzZU51bWJlciB8fAogICAgICAgICAgICAgICAgICAgICAgICB0aGVEYWlseVJlc3VsdHNbaV0ucGxhY2VIb3JzZU51bWJlciA9PSBteUJldC5teUhvcnNlTnVtYmVyIHx8CiAgICAgICAgICAgICAgICAgICAgICAgIHRoZURhaWx5UmVzdWx0c1tpXS5zaG93SG9yc2VOdW1iZXIgPT0gbXlCZXQubXlIb3JzZU51bWJlcikgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbXlCZXQubXlCZXRBbW91bnQgKiAxLjI7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gMDsgLy8gSW52YWxpZCBiZXQgdHlwZQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7IC8vIFJhY2UgbnVtYmVyIG5vdCBmb3VuZCBvciBob3JzZSBkaWQgbm90IHBsYWNlCn0KCmludCBtYWluKCkgewogICAgLy8gRXhhbXBsZSB1c2FnZQogICAgc3RydWN0IHJhY2VSZXN1bHQgdGhlRGFpbHlSZXN1bHRzW1JBQ0VTXSA9IHsKICAgICAgICB7MSwgNSwgMywgOH0sCiAgICAgICAgezIsIDIsIDQsIDF9LAogICAgICAgIHszLCA3LCA2LCA1fSwKICAgICAgICB7NCwgMSwgMywgMn0sCiAgICAgICAgezUsIDQsIDUsIDZ9LAogICAgICAgIHs2LCA4LCA3LCAzfSwKICAgICAgICB7NywgNiwgMiwgNH0sCiAgICAgICAgezgsIDMsIDEsIDd9LAogICAgICAgIHs5LCA1LCA4LCAyfSwKICAgICAgICB7MTAsIDcsIDYsIDF9CiAgICB9OwoKICAgIHN0cnVjdCByYWNlV2FnZXIgbXlCZXQgPSB7MywgNywgMTAwLjAsICdXJ307CiAgICBmbG9hdCB3aW5uaW5ncyA9IG15SG9yc2VCZXQobXlCZXQsIHRoZURhaWx5UmVzdWx0cyk7CgogICAgcHJpbnRmKCJZb3Ugd29uICQlLjJmXG4iLCB3aW5uaW5ncyk7CgogICAgcmV0dXJuIDA7Cn0=