Originally Posted by
TehNeonFishy
I need to have the game show how many coins left in 'o's, how the hell do I do that o.O
Meh.. close enough.. I don't know any algorithms and I'm lazy to find/write one.
C++ Code:
#include <iostream>
void Computer(int &Coins)
{
if (Coins > 11 || Coins == 6)
{
Coins -= 5;
std::cout<<"The computer removed 5 coins leaving a total of: "<<Coins<<std::endl;
}
else if (Coins > 6)
{
Coins -= 1;
std::cout<<"\nThe computer removed 1 coin leaving a total of: "<<Coins<<std::endl;
}
else
{
for (int I = 0; I < Coins; ++I)
{
if (Coins - I == 1)
{
Coins -= I;
std::cout<<"\nThe computer removed "<<I<<" coin(s) leaving a total of: "<<Coins<<std::endl;
}
}
}
}
void Player(int &Coins)
{
int AmountRemoved = 0;
while(true)
{
std::cout<<"\nPlease enter how many coins you'd like to remove: ";
std::cin>> AmountRemoved;
std::cin.ignore();
if (AmountRemoved <= Coins)
break;
}
Coins -= AmountRemoved;
std::cout<<"\nYou removed "<<AmountRemoved<<" coin(s) leaving a total of: "<<Coins<<std::endl;
}
int main()
{
int Coins = 25;
bool WhosTurn = false;
while(Coins != 0)
{
WhosTurn = true;
Computer(Coins);
WhosTurn = false;
Player(Coins);
std::cout<<"\n\n";
}
if (WhosTurn)
std::cout<<"\n\nYou won!"<<std::endl;
else
std::cout<<"\n\nYou Lost!"<<std::endl;
}