# Trouble with IFs

• 03-31-2008
Jingleheimer
Trouble with IFs
Rather than having to input :

If (number= (100*1)+10){
printf("number times a hundred plus ten");

If(number=(100*1)+10){
printf("number times a hundred plus ten");

etc...

Isn't there a way i can condense that into one IF with an Or ||... i've tired it but what ends up happening is any number sent to this subroutine prints the message even though i only want it to print if it specifically meets ((100*1)+10) or ((100*2)+10) etc.

What am i doing wrong ?

• 03-31-2008
vart
= is assignment
== is comparison
• 03-31-2008
Jingleheimer
Oops, my mistake i meant ==, but yeh even then the problem occurs. Cant i set multiple parameters in a single IF ? If so, how ?
• 03-31-2008
matsp

--
Mats
• 03-31-2008
Jingleheimer
If (number= =(100*1)+10){
printf("number times a hundred plus ten");

If(number==(100*1)+10){
printf("number times a hundred plus ten");

Although paraphrased this is essentially the exact same, all i want to know is if i can convert the two IFs above into just one.

If (number= =(100*1)+10) AND HAVE THIS IN HERE TOO (number==(100*1)+10){
printf("number times a hundred plus ten");
• 03-31-2008
laserlight
They test the same condition, so you could write:
Code:

```if (number == (100*1)+10) {     printf("number times a hundred plus ten");     printf("number times a hundred plus ten"); }```
If they were different, you could join them with an || (or).
• 03-31-2008
Elysia
Code:

```if (condition1)     if (condition2)         some_code;```
Is the same as
Code:

```if (condition1 && condition2)     some_code;```
If condition1 AND condition2
It's also possible to do:
Code:

```if (condition1 || condition2)     some_code;```
If condition1 OR condition 2.