<meta property="og:description" content="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 <15): '; cin >> coinCount; } cout << 'We start with ' << coinCount << ' coins' < 0) { // Human takes Coins int takenCoins = 0; while (takenCoins <meta name="twitter:description" content="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 <15): '; cin >> coinCount; } cout << 'We start with ' << coinCount << ' coins' < 0) { // Human takes Coins int takenCoins = 0; while (takenCoins Simple C++ Takeway Game @KTSI - Thomas Maurer

Written by 6:10 pm School

Simple C++ Takeway Game @KTSI

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 &lt;&lt; "Welcome to the TakeAway Game" &lt;&lt; endl &lt;&lt; "====================================" &lt;&lt; endl;
 
	// Input for coinCount
	while (coinCount &lt;= 15) {
		cout &lt;&lt; "Please enter how many coins you wanna use (&gt;15): ";
		cin &gt;&gt; coinCount;
	}
	cout &lt;&lt; "We start with " &lt;&lt; coinCount &lt;&lt; " coins" &lt;&lt; endl; while (coinCount &gt; 0) {
		// Human takes Coins
		int takenCoins = 0;
		while (takenCoins &lt; 1 || takenCoins &gt; 3) {
			cout &lt;&lt; "Please take 1,2 or 3 coins: "; cin &gt;&gt; takenCoins;
		}
		cout &lt;&lt; "You toke " &lt;&lt; takenCoins &lt;&lt; " coins" &lt;&lt; endl;
 
		coinCount -= takenCoins;
		if (coinCount == 0) {
            cout &lt;&lt; "D'OH! you won..." &lt;&lt; endl;
            break;
        }
		cout &lt;&lt; "there are still " &lt;&lt; coinCount &lt;&lt; " coins left" &lt;&lt; endl;
 
		int itakeCoins;
		int tempModu = coinCount % 4;
		if (tempModu == 0) {
			itakeCoins = 1;
		}
		else {
			itakeCoins = tempModu;
		}
		cout &lt;&lt; "I take " &lt;&lt; itakeCoins &lt;&lt; " coins" &lt;&lt; endl;
 
		coinCount -= itakeCoins;
		if (coinCount == 0) {
            cout &lt;&lt; "Ha! I won" &lt;&lt; endl;
            break;
        }
		cout &lt;&lt; "there are still " &lt;&lt; coinCount &lt;&lt; " coins left" &lt;&lt; endl;
	}
    return 0;
}

Tags: , , , , , Last modified: July 5, 2019
Close Search Window
Close