1. Code:
```if(myname == "Me")
{cout << "Hello ME";}
else {
if(myname == "You")
{cout << "Hello YOU";}
}```
is fine as you have closed your 'else' statement.

But in your program you aren't closing them, not until the end, which doesn't work, at least not to my knowledge. It certainly isn't something that is commonly done.

As here
Code:
```else {
if(player.exp < 7000)
{getmonster = 7;}
else {```
You haven't closed the first 'else' before starting the second.

2. Hello,

I copied/pasted your code in vc++6 and it compiled fine (so yes, you can close all your else statements at the end, but that's not pretty. Maybe your parse error is at another place in your program.

3. It's not a function... What I want is so that

if your exp is less than 2000
you can get monsters whose level is 2

or

if your exp is less than 3000
you can get monsters whose level is 3

or

if your exp is less than 4000
you can get monsters whose level is 4

Because otherwise, if it's less than 3000 for example, int getmonster can be 2 OR 3 and that can cause some error.

4. so yes, you can close all your else statements at the end, but that's not pretty
hmmm, i stand corrected. Though it does appear to be a silly that you can, and hideous to read.

5. Korhedron, there are other ways to solve you problem.

One for example is to divide exp by 1000 and add 1 up. If the result is smaller than 2 you can make it 2 and if it's larger than 10 you can make it 10:
Code:
``` getmonster = player.exp / 1000 + 1;

if(getmonster < 2)
getmonster = 2;
else if(getmonster > 10)
getmonster = 10;```
Cheers, Monster

6. Will this end the debate

Code:
```if(condition1)
{
do this1;
}
else if(condition2)
{
do this 2;
}
else
{
do this 3;
}

is equivalent to

if(condition1)
{
do this1;
}
else
{
if(condition2)
{
do this 2;
}
else
{
do this3;
}
}```
The whole point is be it an "if" or an "else", they can have one statement without "{" "}"

when you say else if
what you are stating is that the else has got only one statement and that is another if statement

7. Kohedran are you doing these if statements outside of main? If so, then I think that is your problem. They need to be in a function whether it be main, a member function of mnstr or whatever.

On a side note, my C++ teacher actually specifically told us to never use else if's. He said all of our programs for him had to be done using the nested if else's like what Kohedran has. Ugh, quite the eyesore.

8. Two points.

Korhedron:

Look at the way shiv has formatted his code. Instantly obvious what belongs to what, clear, professional. That style of formatting, (called Allman format), is the most widely used now, numerous studies have shown that the number of errors reading this format is lower than any other, including K+R, Stroustrop and Whitesmith. Look at the confusion your format has created!

I would recomend you adopt the Allman style of coding.

PJ:

>>>
He said all of our programs for him had to be done using the nested if else's like what Kohedran has.
<<<

Well then he is an idiot. However, a point worth bearing in mind, is that when joining an organisation or project group, invariably they will have a set of "coding standards" which will, also invariably, contain some things you won't like. These coding standards will, however, need to be followed - often, the QA department will nit pick over trivial formatting/variable naming/structure usage transgressions, it gives them a feeling of power over a process they can never hope to understand.

9. I agree, which is why I did it in his class but haven't done it since. On a related topic, he also had us write void main() *shudders*

10. just because it compiles doesn't mean it's right

11. Thanks for your posts, but it doesn't solve my problem.

This being one of my first programs, I didn't know about nested ifs and if elses. Now I'll use the if else.

However, I still get this error. My IFs are in a function, and I get an error on that line, and I can't see anything wrong with it. I can't get the code to compile. I think I'll have to retype everything by hand... any ideas before I start that messy job ?

12. Originally posted by Korhedron
any ideas before I start that messy job ?
Yes, post your code or attach your C/C++ file so we can take a look at it.

13. Is the wait to see the code.... everlasting??

Common buddy.....

We can't wait for ever on this