alrite i just started learning c++ 3 days ago and i decided to see what i cud put together with the knowledge ive gained so far. so i made a game, nothing complex by any means, but its a guessing game, i didnt come up with the idea, i just wanted to see if i cud figure out how to do it. so i entered in a code fixed all the errors i could. got all the errors fixed except for the last 1, which i cannot seem to find the problem?
here is the code
#include<iostream>
#include<ctime>
using namespace std;
int main (void);
{
int iUser;
int iGuess = 0;
int iGuesses = 0;
int iNumber = 0;
srand(static_cast<unsigned int>(time(0) ) );
iNumber = rand()%1000+1;
cout << "Enter your name: " << endl;
cin >> iUser
cout << iUser << " Enter a number 1-1000" << endl << endl;
cin >> iGuess
if
{
(iGuess > || < iNumber)
cout << "You got it!!!"
iGuesses ++;
cout << "The number is: " << iNumber
<< endl;
cout << "You took " << iGuesses
<< endl;
}
if
{
(iGuess > iNumber)
cout << "Too high!!!" << endl;
cin >> iGuess
}
if
{
(iGuess < iNumber)
cout << "Too low!!!" << endl;
cin >> iGuess
}
system("PAUSE")
return 0;
}
the error is on line six with the opening curly bracket.
it says "line 6 - expected unqualified-id before '{' token",
and "line 6 - expected ',' or ';' before '{' token"
i dont know if this is just a stupid mistake and im just missing something but ive been over it 100 times and cant seem to find a problem with that bracket or anything else?
any help would be greatly appreciated
thnx
encasing your code in <code></code> (where < is a square bracket like in bbcode ) or pressing hte code button, might look like a # will give it line numbers and syntax highlighting (which is cool)
as to your problem, it is quite possibly caused by the semicolon (;) you have after your main statement.
it should look like this:
1 2
int main (void)
{
i don't believe the void is really necessary.
EDIT:
other problems i think you might have:
1 2 3 4 5 6 7 8 9 10
if
{
(iGuess > || < iNumber)
cout << "You got it!!!"
iGuesses ++;
cout << "The number is: " << iNumber
<< endl;
cout << "You took " << iGuesses
<< endl;
}
this should probably be
1 2 3 4
if (iGuess == iNumber)
{
// your code here
}
putting the comparison inside the code block will probably break it. if not it will enter the code block, run the if statement and then only only affect the next line.