[Solved] Why can’t i check the return of a function with a switch?

It can be done – however your function should be returning an int. int foo(void) { return 1; } int main(void) { switch(foo()) { case 0: printf(“foo\n”); break; case 1: printf(“bar\n”); break; default: break; } return 0; } As, can been seen this compiles and runs. [09:36 PM] $ gcc -Wall -Werror switcht.c -o switcht … Read more

[Solved] == vs. in operator in Python [duplicate]

if 0 in (result1, result2, result3): is equivalent to: if result1==0 or result2==0 or result3==0: What you want is this: if (0,0,0) == (result1, result2, result3): Which is equivalent to: if result1==0 and result2==0 and result3==0: You could actually even do this: if result1==result2==result3==0: since you’re checking to see if all 3 variables equal the … Read more

[Solved] My second if and else if statement produces the wrong answer [closed]

BigDecimal use example vatTotalNoAgeLess5 = BigDecimal.valueOf(dinnerTotal).add(BigDecimal.valueOf(grossTick)).multiply(BigDecimal.valueOf(1.21)).doubleValue(); Example if statement if ((havingDinner.equals(“Y”) || havingDinner.equals(“y”)) && (ageDiscount.equals(“Y”) || ageDiscount.equals(“y”))) { agetick = (grossTick * 0.85); dinnerTotal = dinnerPrice * (standTick + terraceTick); vatTotalForAge = ((dinnerTotal + agetick) * 1.21); System.out.println(vatTotalForAge); } else if ((havingDinner.equals(“Y”) || havingDinner.equals(“y”)) && (ageDiscount.equals(“N”) || ageDiscount.equals(“n”))) { dinnerTotal = dinnerPrice * (standTick + … Read more

[Solved] C++ curly brackets

To answer your first question. By doing an if statement in one line you are limited to one operation, so to speak. if(ret != 0) return false; Whilst using the curly brackets you are declaring a block with code operations. if(ret != 0) { /* do other stuff here */ return false; } There is … Read more

[Solved] python program error elif else if [closed]

if Enter == “Yes” or “yes”: This is not how or works. This is interpreted as if (Enter == “Yes”) or “yes”:. In python, non-empty strings are always true, so all of the if statements like that will be true. I would suggest something like if Enter.lower() == “yes”: which takes care of all of … Read more