Question: WHY WON'T MY CODE EXECUTE?? PLEASE HELP #include #include #include // Function prototypes int GoFish(int bait); void PrintProbabilities(int bait); // Probability tables float wormProbs[4] =

WHY WON'T MY CODE EXECUTE?? PLEASE HELP

#include #include #include

// Function prototypes int GoFish(int bait); void PrintProbabilities(int bait);

// Probability tables float wormProbs[4] = {0.6, 0.25, 0.14, 0.01}; float jigProbs[4] = {0.7, 0.05, 0.2, 0.05}; float chumProbs[4] = {0.8, 0.025, 0.025, 0.15};

// Time and money tables int timeToCatch[4] = {5, 10, 20, 60}; int moneyForCatch[4] = {0, 100, 250, 1000};

int main() { srand(time(NULL)); // Seed the RNG

// Initialize variables int timeRemaining = 720; // 12 hours in minutes int wallet = 0; int baitChoice;

printf("Welcome to Fishing with Various Bait! ");

// Loop until time runs out or user quits while (timeRemaining > 0) { // Print time remaining and wallet balance printf("Time remaining: %d minutes ", timeRemaining); printf("Wallet: $%d ", wallet);

// Prompt user for bait choice printf(" Choose your bait: "); printf("1. Live worms 2. Jig 3. Chum 4. Quit "); scanf("%d", &baitChoice);

// Check for quit option if (baitChoice == 4) { printf(" Thanks for playing! You made $%d today. ", wallet); return 0; }

// Validate input if (baitChoice 3) { printf(" Invalid choice. Please try again. "); continue; }

// Print the catch probabilities for the chosen bait PrintProbabilities(baitChoice);

// Call GoFish function to attempt to catch a fish int fish = GoFish(baitChoice);

// Update time remaining and wallet based on fish caught timeRemaining -= timeToCatch[fish]; wallet += moneyForCatch[fish];

// Print result of fishing attempt if (fish == 0) { printf(" Nothing bit! "); } else { printf(" You caught a "); switch (fish) { case 1: printf("flounder"); break; case 2: printf("red snapper"); break; case 3: printf("shark"); break; } printf("! It took %d minutes to reel in. ", timeToCatch[fish]); printf("You earned $%d. ", moneyForCatch[fish]); } }

// If time runs out, print final wallet balance and exit printf(" Time's up! You made $%d today. ", wallet); return 0; }

// Function to catch a fish using the given bait int GoFish(int bait) { float r = (float)rand() / RAND_MAX; // Generate a random float between 0 and 1 float *probs; // Pointer to the chosen probability table switch (bait) { case 1: probs = wormProbs; break; case

// Define the GoFish function int GoFish(int baitType) { int fishCaught = 0; float randomNum = ((float)rand() / (float)(RAND_MAX)); float prob = 0;

// Determine the fish caught based on bait type and probability if (baitType == 1) { if (randomNum

// Determine if the fish was caught randomNum = ((float)rand() / (float)(RAND_MAX)); if (randomNum

WHY WON'T MY CODE EXECUTE?? PLEASE HELP #include #include #include // Function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!