This is a simple C++ Takeway Game done for KTSI.
#include
using namespace std;
int main (int argc, char * const argv[]) {
// Init
int coinCount = 1;
// Welcome Message
cout << "Welcome to the TakeAway Game" << endl << "====================================" << endl;
// Input for coinCount
while (coinCount <= 15) {
cout << "Please enter how many coins you wanna use (>15): ";
cin >> coinCount;
}
cout << "We start with " << coinCount << " coins" << endl; while (coinCount > 0) {
// Human takes Coins
int takenCoins = 0;
while (takenCoins < 1 || takenCoins > 3) {
cout << "Please take 1,2 or 3 coins: "; cin >> takenCoins;
}
cout << "You toke " << takenCoins << " coins" << endl;
coinCount -= takenCoins;
if (coinCount == 0) {
cout << "D'OH! you won..." << endl;
break;
}
cout << "there are still " << coinCount << " coins left" << endl;
int itakeCoins;
int tempModu = coinCount % 4;
if (tempModu == 0) {
itakeCoins = 1;
}
else {
itakeCoins = tempModu;
}
cout << "I take " << itakeCoins << " coins" << endl;
coinCount -= itakeCoins;
if (coinCount == 0) {
cout << "Ha! I won" << endl;
break;
}
cout << "there are still " << coinCount << " coins left" << endl;
}
return 0;
}
