// Assignment Question 6 Final Exam
//
// Name: <Tasos Paloukos>
//
// Class: C Programming, <Fall 2024>
//
// Date: <December 11, 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;
}
Ly8gQXNzaWd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gLy8gSG93IG11Y2ggbW9uZXkgeW91IGFyZSBiZXR0aW5nCiAgICBjaGFyIGJldFR5cGU7ICAgICAgICAvLyBXIGZvciAiV2luIiwgUCBmb3IgIlBsYWNlIiwgb3IgUyBmb3IgIlNob3ciCn07CgovLyBGdW5jdGlvbiB0byBjYWxjdWxhdGUgdGhlIHdpbm5pbmdzIGJhc2VkIG9uIHRoZSBiZXQKZmxvYXQgbXlIb3JzZUJldChzdHJ1Y3QgcmFjZVdhZ2VyIG15QmV0LCBzdHJ1Y3QgcmFjZVJlc3VsdCB0aGVEYWlseVJlc3VsdHNbXSkgewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBSQUNFUzsgaSsrKSB7CiAgICAgICAgaWYgKHRoZURhaWx5UmVzdWx0c1tpXS5yYWNlTnVtYmVyID09IG15QmV0LnJhY2VOdW1iZXIpIHsKICAgICAgICAgICAgc3dpdGNoIChteUJldC5iZXRUeXBlKSB7CiAgICAgICAgICAgICAgICBjYXNlICdXJzogLy8gV2luCiAgICAgICAgICAgICAgICAgICAgaWYgKHRoZURhaWx5UmVzdWx0c1tpXS53aW5uaW5nSG9yc2VOdW1iZXIgPT0gbXlCZXQubXlIb3JzZU51bWJlcikgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbXlCZXQubXlCZXRBbW91bnQgKiAyOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIGNhc2UgJ1AnOiAvLyBQbGFjZQogICAgICAgICAgICAgICAgICAgIGlmICh0aGVEYWlseVJlc3VsdHNbaV0ud2lubmluZ0hvcnNlTnVtYmVyID09IG15QmV0Lm15SG9yc2VOdW1iZXIgfHwKICAgICAgICAgICAgICAgICAgICAgICAgdGhlRGFpbHlSZXN1bHRzW2ldLnBsYWNlSG9yc2VOdW1iZXIgPT0gbXlCZXQubXlIb3JzZU51bWJlcikgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbXlCZXQubXlCZXRBbW91bnQgKiAxLjU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgY2FzZSAnUyc6IC8vIFNob3cKICAgICAgICAgICAgICAgICAgICBpZiAodGhlRGFpbHlSZXN1bHRzW2ldLndpbm5pbmdIb3JzZU51bWJlciA9PSBteUJldC5teUhvcnNlTnVtYmVyIHx8CiAgICAgICAgICAgICAgICAgICAgICAgIHRoZURhaWx5UmVzdWx0c1tpXS5wbGFjZUhvcnNlTnVtYmVyID09IG15QmV0Lm15SG9yc2VOdW1iZXIgfHwKICAgICAgICAgICAgICAgICAgICAgICAgdGhlRGFpbHlSZXN1bHRzW2ldLnNob3dIb3JzZU51bWJlciA9PSBteUJldC5teUhvcnNlTnVtYmVyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBteUJldC5teUJldEFtb3VudCAqIDEuMjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgICAgIHJldHVybiAwOyAvLyBJbnZhbGlkIGJldCB0eXBlCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsgLy8gUmFjZSBudW1iZXIgbm90IGZvdW5kIG9yIGhvcnNlIGRpZCBub3QgcGxhY2UKfQoKaW50IG1haW4oKSB7CiAgICAvLyBFeGFtcGxlIHVzYWdlCiAgICBzdHJ1Y3QgcmFjZVJlc3VsdCB0aGVEYWlseVJlc3VsdHNbUkFDRVNdID0gewogICAgICAgIHsxLCA1LCAzLCA4fSwKICAgICAgICB7MiwgMiwgNCwgMX0sCiAgICAgICAgezMsIDcsIDYsIDV9LAogICAgICAgIHs0LCAxLCAzLCAyfSwKICAgICAgICB7NSwgNCwgNSwgNn0sCiAgICAgICAgezYsIDgsIDcsIDN9LAogICAgICAgIHs3LCA2LCAyLCA0fSwKICAgICAgICB7OCwgMywgMSwgN30sCiAgICAgICAgezksIDUsIDgsIDJ9LAogICAgICAgIHsxMCwgNywgNiwgMX0KICAgIH07CgogICAgc3RydWN0IHJhY2VXYWdlciBteUJldCA9IHszLCA3LCAxMDAuMCwgJ1cnfTsKICAgIGZsb2F0IHdpbm5pbmdzID0gbXlIb3JzZUJldChteUJldCwgdGhlRGFpbHlSZXN1bHRzKTsKCiAgICBwcmludGYoIllvdSB3b24gJCUuMmZcbiIsIHdpbm5pbmdzKTsKCiAgICByZXR1cm4gMDsKfQ==