REEILYMods
Modder
- Messages
- 65
- Reaction score
- 37
- Points
- 568
Hello community!
I'm always trying to improve my C++ skills and I'm on a good way!
Today I'm releasing a small numbergame,
that cost me a lot of nerves!
I'm always trying to improve my C++ skills and I'm on a good way!
Today I'm releasing a small numbergame,
that cost me a lot of nerves!
-Me
.A good book for learning C++
( It's german so it's useless to give the name )
.A good book for learning C++
( It's german so it's useless to give the name )
Code:
//Sadly I used german declarations for ints, the long long and the bool!
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
bool gefunden = false;
char input = 'w';
int zahl, versuch, ratezahl;
long long sek;
time(&sek);
srand((unsigned)sek);
while (input == 'w')
{
system("cls");
cout << "*** A NUMBERGAME ***\n"
<< "Spielregeln:\n"
<< "# 1 I'm going to generate a number between 0 and 15!\n"
<< "# 2 You have 3 tries to guess the number!\n"
<< "And now have fun!"
<< endl;
zahl = (rand() % 15 + 1);
versuch = 0;
while (!gefunden && versuch < 3)
{
cin.sync();
cin.clear();
cout << ++versuch << ". Try" << endl;
cin >> ratezahl;
if (ratezahl < zahl)
cout << "Your number is too small!" << endl;
else if (ratezahl > zahl)
cout << "Your number is too big!" << endl;
else
gefunden = true;
}
if (!gefunden)
cout << "I have won! The number was: " << zahl << endl;
else
cout << "Nice! You have won and bet the MASTER!" << endl;
cout << "Would you like to restart? Enter [w] to restart, [q] to quit!"
<< endl;
do
cin.get(input);
while (input != 'w' && input != 'q');
}
system("pause");
return 0;
}