Help with functions/call functions

Dev-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,
should 'bool declare_winner' be written: 'void declare_winner'?

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 #include <iostream>
using namespace 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)
}

I think you need to add a () along with its parameters in the function prototype
Oh thanks! sorry I didn't see that
Topic archived. No new replies allowed.