Question: This code ( Vscode with homebrew GNU Compiler Collection gcc 1 4 ) has three tasks to complete ( three tasks are listed in the
This code Vscode with homebrew GNU Compiler Collection gcc has three tasks to complete three tasks are listed in the code to reach the desired outputincluded at the bottom Please may any experts help me with this? Thank you very much for your helping.
#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 ;
Output wining output:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
Enter the number of cannibals to move:
Bank : missionaries, cannibals
Bank : missionaries, cannibals
Boat is at bank
Enter the number of missionaries to move:
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
