Question: Please complete the C + + code given #include using namespace std; int main ( ) { / / m 1 - number of missionaries
Please complete the Ccode given
#include
using namespace std;
int main
m number of missionaries at bank
c number of cannibals at bank
m number of missionaries at bank
c number of cannibals at bank
b boat position or
lose a boolean to indicate whether missionaries are eaten
Initial state: missionaries and cannibals at bank missionaries and cannibals at bank boat at bank
int m c m c b ;
bool lose false;
Task : Winning condition
When the winning condition is not met, continue the game
while YOUR CODE HERE
Print the current state before each move
cout "Bank : m missionaries, c cannibals" endl;
cout "Bank : m missionaries, c cannibals" endl;
cout "Boat is at bank b endl;
Task : Input and move
Read the number of missionaries and cannibals to move and update relevant
variables. Read missionaries first and then cannibals. You also need to
output the prompt, so put the following two "cout" statements to
appropriate places.
cout "Enter the number of missionaries to move: ;
cout "Enter the number of cannibals to move: ;
You don't need to validate the input, which means you may assume:
The input is never negative
The input is no larger than the number of missionaries or cannibals at the bank
The number of people on board is always between and
Our demo programs provide input validation. If you are interested, you can also try
to validate the input yourself, but this won't be tested in ZINC testcases.
However, it is POSSIBLE that an input leads to a losing condition missionaries eaten
YOUR CODE HERE
Task : Losing condition
If the losing condition is met after a move, set "lose" to true and then break
the loop to stop the game
YOUR CODE HERE
Print the final state
cout "Bank : m missionaries, c cannibals" endl;
cout "Bank : m missionaries, c cannibals" endl;
if lose
cout "Missionaries been eaten! Game over!" endl;
else
cout "You win!" endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
