Welcome to the Parallax Discussion Forums, sign-up to participate.

# Making complicated decisions

Posts: 32
Does anyone know how I would modify a or b to make it only print one message? I am working on the "make complicated decisions" part on parallax's website.

int main() // main function
{
int a = 17; // Initialize a variable to 25
int b = 17; // Initialize b variable to 17
print("a = %d, b = %d\n", a, b); // Print all
if((a > b) || (a == 100)) // If a > b OR A == 100
{
print("a might be larger than b, \n"); //Then print this message
print("OR a might be 100, \n"); //Then print this message
print("OR mabey both!\n"); //Then print this message
}
}

• Posts: 2,129
edited April 2017
You can't print only one message with certain a, b values. If the condition is true all of them get printed out, it's one block of print commands.

If you want the messages dependent of the values, you need separate IF tests:
```  if(a > b)
{
print("a is larger than b, \n");
}
if(a == 100)
{
print("a is 100, \n");
}
if((a > b) && (a == 100))
{
print("both!\n");
}
```

Andy
• Posts: 5,891
edited April 2017
Your first to if statements have an extra left parenthesis, Andy.
Jon McPhalen
Hollywood, CA
It's Jon or JonnyMac -- please do not call me Jonny.
• Posts: 2,129
Thank's Jon
I have it edited
• Posts: 895
Ariba - don't you want some else statements and reordering so that only one is printed?
• Posts: 13,132
KeithE wrote: »
Ariba - don't you want some else statements and reordering so that only one is printed?
Not necessary, but the code will be slower as it has to test each if statement.
Could also be done with a switch/case method.
My Prop boards:
Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
Website: www.clusos.com
• Posts: 895
I just mentioned it since the original post said: "make it only print one message"