# Thread: Why is my if statement not working? No matter the input it always chooses N

1. ## Why is my if statement not working? No matter the input it always chooses N

Code:
```#include <stdio.h>int Sum();
double ArcLength();
int main() {
int result1, result2;
double s;
result1 = Sum();
result2 = Sum();
s = ArcLength();
printf("First sum = %d, Second sum = %d\n", result1, result2);
printf("Arclength = %lf meters", s);

}
int Sum() {
int a, b, c;
printf("Enter a value for a: ");
scanf("%d", &a);
printf("Enter a value for b: ");
scanf("%d", &b);
printf("Enter a value for c: ");
scanf("%d", &c);
//printf("The sum of a, b, and c is: %d\n", a + b + c);
return a + b + c;
}
double ArcLength() {
double r, AngleR, AngleD;
char choice;
printf("Input radius in meters for circle: ");
scanf("%lf", &r);
printf("Do you have an angle value in radians? (Y or N): ");
scanf(" %c", &choice);
if (choice == 'n' || 'N') {
printf("Enter an angle in degrees: ");
scanf("%lf", &AngleD);
printf("Input an angle in radians: ");
scanf("%lf", &AngleR);
}
else if(choice == 'y' || 'Y') {
printf("Input an angle in radians: ");
scanf("%lf", &AngleR);
}

return r * AngleR;
}```

2. Compound control statements require both sides of the comparison for every condition.

Code:
`if(a < b || c < b)`

3. Code:
`if (choice == 'n' || 'N')`
This line doesn't compare choice to two different character constants; it first compares choice to the letter 'n', and if that fails, it then checks whether the letter 'N' exists. Since the letter 'N' does in fact exist, this statement will always be true.

If you want to compare choice to two different letters, then you need to have a comparison with choice on both sides of the || operator.

4. I get what you're trying to say to some extent, but cannot figure out how to put that into code. I'm just practicing before my test today and need to know how to do it.

5. Hi,

[...]
Originally Posted by alpinanazawsze
Code:
```    if (choice == 'n' || 'N') {

}```
[...]

use:

Code:
`    if(tolower(choice)=='n')`

6. Originally Posted by alpinanazawsze
Code:
`if (choice == 'n' || 'N')`
Originally Posted by tabstop
it first compares choice to the letter 'n' (...) you need to have a comparison with choice on both sides of the || operator
I get what you're trying to say to some extent, but cannot figure out how to put that into code. I'm just practicing before my test today and need to know how to do it.
Read more carefully what was written! The comparison to 'n' does what you want, but you need to do the same on the other side of the || operator (for 'N'). Should become clear then.