Hi there, it's my first post here.
I'm new in C++ some would even say that I'm a complete...
I was trying differend things, started with simple console programming and
ended at getting some idea about WinAPI. I couldn't find any good solution
to make further progress in learning. I went back where I started.
So yeah, that's my main problem.
I was trying to make my old guess game more complex,
and it looks like I'm not even able to do this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string input;
bool won=false,
con;
int right,
user;
cout << "PC: Hi there, let's play a game.\n "
"I take a number between 1 and 100, you gonna guess it.\n\n "
"To Play, let me know what's your name.\n "
"If you want to exit answer me with a NO.\n\n ";
cin >> input;
cin.ignore();
std::transform(input.begin(), input.end(),input.begin(), ::toupper);
while(con){
cout << " Hi " << input << "." << endl;
srand (time(NULL));
right=rand() % 100;
cout << right;
int lifes=5;
cout << " So let's start! "
"I have choosen my number already, now guess it.\n"
"You have 5 lifes.\n" << endl;
cin >> user;
cin.ignore();
while(lifes>=1){
if(input=="NO"){!con;}
--lifes;
if(right<user){
cout << "No way, my number is smaller. "
"You have still " << lifes << " life/s.\n";
cin>>user;
}
else if(right>user){
cout << "Nope, my number is higher. "
"You have still " << lifes << " life/s.\n";
cin>>user;
}
else{
cout << "Nice one, you won!";
won=true;
}
cin.ignore();
}
cout << "Game Over! Press enter to restart or type NO to exit.";
cin.get();
}
return 0;
}
|
That's my code. It is far from "clean", because of many tests,
but I hope you will get my idea. Maybe any kind person could help me out.