Question: PASS BY VALUE FUNCTIONS 1.Modify the 13 eggs problem from Lab 3. Write a function that makes the selection for the Tortoise. The prototype for

PASS BY VALUE FUNCTIONS

1.Modify the 13 eggs problem from Lab 3.

Write a function that makes the selection for the Tortoise. The prototype for the function is

int tortoisePick(int numberEggs, int harePicked)

There is a strategy that you can use so that the Tortoise always wins. When the function is called, if numberEggs is equal to 13, the tortoise is making the first selection. If numberEggs is not equal to 13, the hare has made a selection and the hare?s selection was passed as the second parameter, harePicked. The return value is the number of eggs that the Tortoise selects. Hint: After the hare picks, if the tortoise makes a selection so that the sum of both picks is 4, then the tortoise will always be the winner, since 12 is evenly divisible by 4.

There is the Lab3 13 eggs problem,

 PASS BY VALUE FUNCTIONS 1.Modify the 13 eggs problem from Lab

13 eggs problem.cpp

#include

using namespace std; int main() {

// Use of a flag to control the game // The program plays the role of the "Judge" for the game // - program askes for a valid selection // - program determines if the game is over // - program declares the winner

bool gameOver = false; // flag int numberEggs = 13; int player = 1; // 1 for Tortoise , 2 for Hare int selected; while (!gameOver) { cout > selected; // If move is legal: 1 to 3 eggs and no more than numEggs remaining

if (selected = 1 && numberEggs >= selected) // student supplies code { numberEggs -= selected; // student supplies code

if (numberEggs > 0) // student supplies code { player = (player % 2) + 1; // student supplies code } else { gameOver = true; } } else // not a valid selection { cout

//declare the winner cout

return 0;

} // end main

**I searched this question online and all of them had errors in their codes.

In order to received 5 stars review please post the codes without bugs. Thanks!**

Problem 2 13 Eggs Problem A tortoise and the hare saw 13 Easter eggs in the yard. Both the tortoise and the hare wanted all of the eggs for themselves, so they decided to divide them up among themselves. They would alternate turns and in each turn one to three eggs would be taken. If more than 3 eggs are selected, the selection was illegal and the selection should be made again. They agreed that whichever one took the last egg would be able to keep all of the 13 eggs. The tortoise, being the slowest, was allowed to have the first turn. Third Set of Data First Set of Data The turns were as follows: Tortoise Hare Eggs Left lare Eggs Left 13 12 Tortoise Hare ERROR ERROR 0 0 Winner is: Tortoise Winner is: Hare ond Set of Data Tortoise Hare Eggs Left 13 Winner is: Hare

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!