I need help figuring out how to work this program.
c++ is telling me:`init_game' cannot be used as a function, along with 'ask_move' , and 'declare_winner'. Also a bit curious with void functions,
Rules of game:
• The game starts out with the user choosing the initial number of chips. It must be between 2 and
50 inclusively.
• Players alternate turns removing no more than half of the remaining
chips
• Whichever player takes the last chip wins the game.
#include <iostream>
usingnamespace std;
int init_game;
int ask_move;
bool is_move_legal;
bool declare_winner;
int main()
{
bool player1turn = true;
bool game_over = false;
int chips_in_pile = init_game();
while (game_over == false)
{
int chips_taken = ask_move(player1turn, chips_in_pile);
chips_in_pile = chips_in_pile - chips_taken;
if (chips_in_pile == 0)
{
game_over = true;
declare_winner(player1turn);
}
else
{
cout << "There are " << chips_in_pile << " chips left." << endl << endl;
player1turn = !player1turn;
}
}
return(0);
}
void declare_winner (bool player1turn)
{
if (player1turn = true)
{
cout << " Congratulations Player 1! You won the game of chips." << endl;
else
{
cout << "Congratulations Player 2! You won the game of chips. " << endl;
}
}
bool is_move_legal(int chips_taken, int chips_in_pile)
{
if (chips_taken !>= (chips_in_pile/2))
{
cout << "Sorry that was not a legal move. Try again. ";
cin >> chips_taken;
is_move_legal(chips_taken)
else
{
return (chips_taken)
}
}
}
int ask_move(bool player1turn, int chips_in_pile)
{
if (player1turn = true)
{
cout << "Player 1 - how many chips would you like to take? ";
cin >> chips_taken;
is_move_legal(chips_taken)
else
{
cout << "Player 2 - how many chips would you like to take? ";
cin >> chips_taken;
is_move_legal(chips_taken)
}
return (chips_taken)
}
int init_game()
{
cout << "How many chips do you want to start with? (2-50 inclusive)";
cin >> chips_in_pile;
if ((chips_in_pile <= 2) || (chips_in_pile >= 50))
{cout << "Sorry you must enter a number between 2 and 50 inclusive, Try again";
cim >> chips_in_pile;
}
return (chips_in_pile)
}
void declare_winner (bool player1turn)
{
if (player1turn = true)
{
cout << " Congratulations Player 1! You won the game of chips." << endl;
else
{
cout << "Congratulations Player 2! You won the game of chips. " << endl;
}
}