So debugging my program,and this error shows up, along with many others for the different functions.
"'easy' : local function definitions are illegal
1> c:\users\hrikhu\documents\visual studio 2010\projects\game\game\main.cpp(26): this line contains a '{' which has not yet been matched"
I really don't understand what this means, and heres the code where the error occurs.
void easy ()
{
cout << "\nIn this game mode, easy, you must guess the secret number between 0 and 100.\n You have 5 guesses\n";
int wine=59; int guesse; int loop=0; guess: do { cin >> guesse;
if (guesse == wine) {cout << "\nYAY! You won!\n"; int main (); }
if (guesse < wine) {cout << "\nToo low\n"; loop=loop+1; goto guess;}
if (guesse > wine) {cout << "\nToo high\n"; loop=loop+1; goto guess;}
if (loop > 5) {cout << "\nSorry, you lost.\n"; break;}
} while (loop > 5);
}
This is like the other functions, so helping me fix this one would help a lot. Thanx.
The names are not identical. You see, the variable ends with an 'e' and the label does not.
However I have a new question.
When you define functions, like this:
"int play ();
void diff ();
void easy ();
void medium ();
void hard ();
int main ();
"
when you call the function do you end the function declaration with a semi colon such as this:
"void easy ();
{
cout << "\nIn this game mode, easy, you must guess the secret number between 0 and 100.\n You have 5 guesses\n";
int wine=59; int guesse; int loop=0; guess: do { cin >> guesse;
if (guesse == wine) {cout << "\nYAY! You won!\n"; int main (); }
if (guesse < wine) {cout << "\nToo low\n"; loop=loop+1; goto guess;}
if (guesse > wine) {cout << "\nToo high\n"; loop=loop+1; goto guess;}
if (loop > 5) {cout << "\nSorry, you lost.\n"; break;}
} while (loop > 5);
}
"
It seemed to have stopped all but a few easily fixed errors.
I use Microsoft 2010 Express.
Is it something specific to this compiler?
void easy(); declaration easy(); call. n = abs(n); another call example (now passing parameters and catching the returned value)
That said, you are not calling the 'easy' function in your program.
_ Horrible indentation
_ You do know that you can return values from functions, ¿right?
_ If it is not equal or less, it ought to be greater.
_ ¿Why are you checking loop>5 twice?
_ You can't call main(). It's against the standard.
Pardon my indentation. I didn't know that there is indentation in C++.
Yes, I know functions can return values. I wrote this when I was even more of a novice.
I also know that if i use more advanced C++, I can make this code 3 time shorter, but i wanna make this work first.
The new thing i learned is that there are indentations, and you cant call main ().
My code works now, it builds correctly, however there is an unwanted exit thing happening in my program.
Heres the code"
int main ()
{
cout << "Welcome to a C++ guessing game.\n";
cout << "Would you like to play\?\nY/N\?\n";
char yom;
cin >> yom;
if ((yom == 'n') | (yom == 'N')) {cout << "\nGoodbye!"; return 0;}
if ((yom == 'y') | (yom == 'Y')) {void diff ();}
else ((yom != 'n') | (yom != 'N') | (yom != 'y') | (yom != 'Y')); {cout << "\n"; int main ();}
}
\\and heres where the program goes if yom = y or Y