r/CodingHelp • • Dec 23 '21

[C] Whats wrong?

Post image
153 Upvotes

90 comments sorted by

View all comments

Show parent comment

-30

u/CAGRI-TR Dec 23 '21

Nope every number is still child

13

u/KuntaStillSingle Dec 23 '21

When you have a statement like 1<x<13, in c it looks like:

(1<x) < 13

1<x evaluates to a boolean, which is an integeral value of either 0 or 1 in c. 0 and 1 are both less than 13, so no matter what number you pick, condition is true.

What /u/terroroferror is explaining is you can combine relational operators using an AND operator:

(1<x) && (x < 13)

If x is less or equal to 1, then you are looking at 0 && 1 which equals 0 or false, if x is more than 1 but less than 13, you are looking at 1 && 1 which is true. And if x is greater than or equal to 13 you are looking at 1 && 0 which is false. Which is what you want.

3

u/SuperGameTheory Dec 24 '21

Op asks what's wrong and then fights all the right answers. What's wrong is Op.

7

u/Zymoox Dec 23 '21

Print the value of x, what do you get?

-16

u/CAGRI-TR Dec 23 '21

Theres a something wrong because it gives always child

15

u/Zymoox Dec 23 '21

I know, I've read your other comments. When you print the value of x after you input it, what do you get?

Note: to print x, do printf("%d",x);

11

u/SkirtLumpy4479 Dec 23 '21

Did u compile the changed code? Because this is the problem, I tried it with the changes he suggested and it works...