Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

#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 by4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

3. Have the group identify common themes.

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago