Re: why does this code not work

You may not put the braces if your if statement is only going to contain one line of code as its conclusion. i hope that makes sense. To make it more clear, here's an example that will work.
void main()
{
int age=3;
if(age==3)
alert("3", "you are 3 years old");
else if(age == 4)
alert("4", "You are 4 years old");
else
alert("out of range", "Your age is out of my calculation range");
}
So. If I wanted to increase the age  variable by one unit when the alert about being 3 years old shows up, I should have placed braces. So it would look like this:
void main()
{
int age=3;
if(age==3)
{
alert("3", "you are 3 years old");
age+=1;
}
else if(age == 4)
alert("4", "You are 4 years old");
else
alert("out of range", "Your age is out of my calculation range");
}
Don't panic if You don't see the alert relevant to age of 4 show up. It's because I used an else statement so the program checked it all when the age was 3. Saw that the age is nor 4 neither out of range so it executed the if statement relevant to the age of 3. If you delete the "else " word before the if statement of age 4, You'll see the alert relevant to the age of 4 pops up right after the first alert because instantly after you press the ok button of the first alert, age variable increases by one unit and then the second alert shows up.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : bopitmaster34 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : bopitmaster34 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Liam via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : simter via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector

Reply via email to