c++ Number guessing game

#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <conio.h>

using namespace std;

int main ()
{
bool again=true;
string name, answer;
float guess, age, secret_number, level, upoints=0, ppoints=0;
int i=1, j=1 ,k=1;
int level1_guesses = 0, level2_guesses = 0, level3_guesses = 0;
srand((unsigned)time(0));

cout << "\n\t\t The Guessing Game!"
<< "\n\t\t ==================";

cout << "\n\nEnter name: ";
getline (cin, name);

cout << "\n" << name << ", please enter your age: ";
cin >> age;

cout << "\nPlayer Profile!"
<< "\n------------------";
cout << "\nName: " << name;
cout << "\nAge: " << age;
cout << "\nUser Points\t: " << upoints;
cout << "\nProgram Points\t: " << ppoints
<< "\n------------------"
<<"\n\n";

cout << "\nPlease choose difficulty level. "
<< "\n(1) Easy."
<< "\n(2) Medium."
<< "\n(3) Hard."
<< "\nInput: ";
cin >> level;
if (level == 1)
{
while(again){
int i=10;
while (i>0){
secret_number = rand () % 100 + 1;
cout << "\nGuess a number between 1-100: ";
cin >> guess;

if(k<0) {
upoints = upoints + 1;
cout << "\nUser Points =" << upoints;
}
else upoints = 0;

if(guess == 999)
{
return 0;
}

else{
level1_guesses = level1_guesses + 1;
if (guess < secret_number){
cout << "\nToo small, try again!\n\n" << level1_guesses;
}
else if ( guess > secret_number){
cout << "\nToo big, try again!\n\n" << level1_guesses;
}
else if(guess == secret_number)
cout << "\nWell done, you guessed it!\n\n";

}
--i;
};

cout << "\n GAME OVER\n";
ppoints = ppoints + 1;
cout << "\nProgram Points = " << ppoints;
cout << "\nUser Points =" << upoints;
cout << "\n DO YOU WANT TO PLAY AGAIN (Y / N)\n";
cin >> answer;
{
if(answer == "Y")
{

again=true;

}
else if(answer == "N")
{
return 0;
}
else if(answer != "N" && "Y")
{
cout << "\n Invalid !\n";
return 0;
}

}


}

}

else if (level == 2)
{
while(again){
int j=5;
while (j>0){
secret_number = rand() % 100 + 1;
cout << "\nGuess a number between 1-100: ";
cin >> guess;


if(k<0) {
upoints = upoints + 1;
cout << "\nUser Points =" << upoints;
}
else upoints = 0;

if(guess == 999)
{
return 0;
}

else{

level2_guesses = level2_guesses + 1;
if (guess < secret_number){
cout << "\nToo small, try again!\n\n" << level2_guesses;
}
else if ( guess > secret_number){
cout << "\nToo big, try again!\n\n" << level2_guesses;
}
else if(guess == secret_number)
cout << "\nWell done, you guessed it!\n\n";


}

--j;
};


cout << "\n GAME OVER\n";
ppoints = ppoints + 1;
cout << "\nProgram Points = " << ppoints;
cout << "\nUser Points =" << upoints;
cout << "\n DO YOU WANT TO PLAY AGAIN (Y / N)\n";
cin >> answer;
{
if(answer == "Y")
{

again=true;

}
else if(answer == "N")
{
return 0;
}
else if(answer != "N" && "Y")
{
cout << "\n Invalid !\n";
return 0;
}

}

}


}

else if (level == 3)
{
while(again){
int k=3;
while (k>0){
secret_number = rand() % 100 + 1;
cout << "\nGuess a number between 1-100: ";
cin >> guess;

if(k<0) {
upoints = upoints + 1;
cout << "\nUser Points =" << upoints;
}
else upoints = 0;

if(guess == 999)
{
return 0;
}

else{

level3_guesses = level3_guesses + 1;
if (guess < secret_number){
cout << "\nToo small, try again!\n\n" << level3_guesses;
}
else if ( guess > secret_number){
cout << "\nToo big, try again!\n\n" << level3_guesses;
}
else if(guess == secret_number)
cout << "\nWell done, you guessed it!\n\n";


}


--k;
};

cout << "\n GAME OVER\n";
ppoints = ppoints + 1;
cout << "\nProgram Points = " << ppoints;
cout << "\nUser Points =" << upoints;
cout << "\n DO YOU WANT TO PLAY AGAIN (Y / N)\n";
cin >> answer;
{
if(answer == "Y")
{

again=true;

}
else if(answer == "N")
{
return 0;
}
else if(answer != "N" && "Y")
{
cout << "\n Invalid !\n";
return 0;
}

}

}


}
else if (level == 999)
{
return 0;
}

else
cout << "\nInvalid input!!, Try Again\n\n";
return 0;

}
Last edited on
Please state the compiler error and put you code in tags...
Is this a question that solved itself? o_o

Zeillinger : yes

xander333 :

Setting environment for using Microsoft Visual Studio 2010 x86 tools.

C:\Program Files\Microsoft Visual Studio 10.0\VC>cd ..

C:\Program Files\Microsoft Visual Studio 10.0>cd..

C:\Program Files>cd..

C:\>cd users

C:\Users>cd randipro

C:\Users\randipro>cd desktop

C:\Users\randipro\Desktop>cl /EHsc Guessing_The_Game.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

Guessing_The_Game.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:Guessing_The_Game.exe
Guessing_The_Game.obj

C:\Users\randipro\Desktop>Guessing_The_Game

The Guessing Game!
==================

Enter name:
, please^C
C:\Users\randipro\Desktop>Guessing_The_Game

The Guessing Game!
==================

Enter name:
Topic archived. No new replies allowed.