rendered paste body//Game of Nim
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
do
ifstream infile;
string player1, player2;
int pile, error=0;
infile.open ("c:\Documents and Settings\Prit-Kamar Sandhu\My Documents\NimGame.txt");
if (!infile)
cout << "Error, file not found. Please choose another destination." << endl;
error = error + 1;
} while (error=1)
else
cout << "Loading..."<< endl;
while (infile!=0)
{
infile >> player1;
cout << player1 << endl;
infile >> pile;
cout << pile << endl;
infile >> player2;
cout << player2 << endl;
while (pile!=1)
{
int number1, number2;
cout << "How many marbles will" << player1 << " take from the pile? (maximum: half
<< "of pile)" << endl;
cin >> number1;
pile = pile - number1;
if (pile=1)
{ cout << player1 << " has won the game. Congratulations!" << endl;
break; }
cout << "There are " << pile << " marbles left in the pile." << endl;
cout << "How many marbles will" << player2 << "take from the pile?"
<< "(maximum: half of pile)" << endl;
cin >> number2;
pile = pile - number2;
if (pile=1)
{ cout << player2 << " has won the game. Congratulations!" << endl;
break; }
cout << "There are " << pile << " marbles left in the pile." << endl;
cout << "How many marbles will" << player2 << " take from the pile? (maximum: half
<< "of pile)" << endl;
cin >> number2;
}
}
return 0;