0
#include <iostream>

using namespace std;

//-----------------------------------------------------------------------------
void UserMove(int &NumStones)
/* Pre: NumStones > 0
 Post: User has taken 1, 2, or 3 stones from pile */
{
 cout << "How many would you like? ";
 int TakeStones;
 cin >> TakeStones;
 while (TakeStones<1 || TakeStones>3 || TakeStones>NumStones) {
  cout << "Value must be between 1 and 3" << endl;
  cout << "How many would you like? ";
  cin >> TakeStones;
 }
 NumStones-=TakeStones;
}
//-----------------------------------------------------------------------------
void ComputerMove(int &NumStones)
/* Pre: NumStones > 0
 Post: Computer has taken 1, 2, or 3 stones from pile */
{
 int TakeStones;
 do {
  TakeStones=1+random(3);
 } while (TakeStones<1 || TakeStones>3 || TakeStones>NumStones);
 cout << "The computer takes " << TakeStones << "." << endl;
 NumStones-=TakeStones;
}

int main()
{
    UserMove();
    ComputerMove();
    system("PAUSE");
    return 0;
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by VernonDozier
0
#include <iostream>

using namespace std;

//-----------------------------------------------------------------------------
void UserMove(int &NumStones)
/* Pre: NumStones > 0
 Post: User has taken 1, 2, or 3 stones from pile */
{
 cout << "How many would you like? ";
 int TakeStones;
 cin >> TakeStones;
 while (TakeStones<1 || TakeStones>3 || TakeStones>NumStones) {
  cout << "Value must be between 1 and 3" << endl;
  cout << "How many would you like? ";
  cin >> TakeStones;
 }
 NumStones-=TakeStones;
}
//-----------------------------------------------------------------------------
void ComputerMove(int &NumStones)
/* Pre: NumStones > 0
 Post: Computer has taken 1, 2, or 3 stones from pile */
{
 int TakeStones;
 do {
  TakeStones=1+random(3);
 } while (TakeStones<1 || TakeStones>3 || TakeStones>NumStones);
 cout << "The computer takes " << TakeStones << "." << endl;
 NumStones-=TakeStones;
}

int main()
{
    UserMove();
    ComputerMove();
    system("PAUSE");
    return 0;
}

Function in line 6 expects a parameter. Your function call does not provide one in line 35. Same thing for your function call in line 36. you need to define an integer in main, then pass that integer to each function in your function calls. Initialize this variable to be the number of stones that exists before the game starts, then call your functions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.