-
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 ?
Please and thank you :).
-
= is assignment
== is comparison
-
Oops, my mistake i meant ==, but yeh even then the problem occurs. Cant i set multiple parameters in a single IF ? If so, how ?
-
Please post your ACTUAL code, not paraphrased code.
--
Mats
-
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");
-
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).
-
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.