#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;
}
R4zrF1r3 0 Newbie Poster
VernonDozier 2,218 Posting Expert Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.