I must make a Nim game. SO far the computer will not make smart moves, and the invald intry will only work once then you can remove more coins from the pile then max number of coins
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main (){
int num, coins, compturn,turnSize,pileSize; // Declaration of Variables
char firstturn;
bool winner = false; //This statement says that the winner is false until declared (When no coins are left)
cout << "Welcome to NIM"<< endl;
cout << "How many coins would you like in the pile?"<<endl;
cin >> coins;
cout<<"How many coins can you remove per turn"<<endl;
cin>>turnSize;
cout<<"Should the user or computer go first (C or U)"<<endl;
cin>> firstturn;
//While there is no winner, the body of the loop is run.
while (!winner){
if (firstturn == 'u' || firstturn =='U')
{ if(coins >= 0){
cout << "There are " << coins << " coins in the pile.\n"
<< "How many would you like to take from this pile" << endl;
cin >> num;
cout << "You have removed " << num << " coins from the pile." << endl;
//This subtracts the number removed from the total number of coins in the pile.
coins -= num;
cout << "There are " << coins << " left in the pile." << endl;
{ cout<<"Invalid Move my friend!! :("<<endl;
cout<<"Please re-enter your amount"<<endl;
cin>>num;
}
//If the amount of coins reaches 0 during the user's turn, the user will be declared winner.
if(coins == 0){
winner = true;
cout << "You win, You have played a good game :) Congratulations!" << endl;
}
//If the user tries to enter a removable number of coins that is larger than the number
//left in the pile, then they are prompted to enter a more acceptable amount.