Question
Note: Can ignore the comment. They were made when the program was first made. I wrote everything out, yet the function isn't acting how I
Note: Can ignore the comment. They were made when the program was first made.
I wrote everything out, yet the function isn't acting how I need it to act. I will post the instruction shortly after this explanation. I imagine I need to remove cin >> eggsSelected, but doing so causes an infinite loop. If I keep as is, then I have to pick the amounts, thus defeating the purpose of the function. I'm assuming I need to remove the cin line and use an if else statement inside a while loop. Any help would be appreciated. Thank you.
#include
using namespace::std;
int tortoisePick(int, int);
void main()
{
bool gameOver = false; // flag
int numberEggs = 13; // 13 eggs total
int player = 1; // 1 for Tortoise , 2 for Hare - Tortoise is alway first
int eggsSelected; // the amount of eggs the player takes per turn. Number must follow appropriate rules
int hareSelect = 0;
while (!gameOver) // While the game is not over
{
cout
eggsSelected = tortoisePick(numberEggs, hareSelect);
cin >> eggsSelected; // input of player
if (1
{
numberEggs -= eggsSelected; // used to calculate the new value of numberEggs after the player has taken "x" amount
if (numberEggs > 0) // if the amount of eggs left is above 0, then the game will continue running
{
(player ? (player == 1 ? player = 2 : player = 1) : player = 1); // switches to the next player
}
else
{
gameOver = true; // flag for our while loop. Loop will stop iterating when gameOver is true
}
}
else // not a valid selection. player inputs an illegal amount
{
cout
}
cout
} // end while
cout
return; // indicates successful termination
} // end main
int tortoisePick(int numberEggs, int hareSelect)
{
int pick = 0;
if (numberEggs == 13)
pick = 1;
else if (numberEggs != 13)
hareSelect;
else if (hareSelect == 2)
pick = 2;
else
pick = 3;
return pick;
}
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 by4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started