// NIM game!
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int main()
{
int total, n;
cout << "Please enter a number between 1 and 7 and press ENTER:" << endl;
cin >> total;
if (total>=7 || total<=1)
{ cout << "Please enter a number between 1 and 7 and press ENTER:" << endl;
}
else{
while (true) {
if ((total % 3) == 2){
total = total - 2;
cout << "I am subtracting 2." << endl;
}else{
total--;
cout << "I am subtracting 1." << endl;
}
cout << "New total is" << total << endl;
if (total == 0) {
cout << "I win!" << endl;
break;
}
cout << "Enter number to subtract between 1 and the new total: ";
cin >> n;
while (n < 1 || n > total) {
cout << "Input must be between 1 and new total." << endl;
cout << "Re-enter: ";
cin >> n;
}
total = total - n;
cout << "New total is " << total << endl;
if (total == 0) {
cout << "You Win!" << endl;
break;
}
system("PAUSE");
return 0;
}
}
}