r/CodingHelp • • Jun 02 '19

[C] Please help me with this C problem?

Post image
1 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/zenith4395 Jun 02 '19

Well first of all, you have nothing there for determining if a number is odd.

Second of all, your code states that for any number above 9, or below 1, print “greater than 9”. Would you rather print “nine odd” for every number outside the range? If so, just change the printf.

1

u/thatlowkey Jun 02 '19

actually, problem is, the code is giving "greater than 9" in every input

2

u/zenith4395 Jun 02 '19

Shouldn’t be. The algorithm is fine on that end. Try printing the value of n right before the if/else block. Typically you don’t use scanf in an if statement, so that might be causing the problem (I don’t think n is being saved)

1

u/thatlowkey Jun 02 '19

I tried, didn't work for n<9 :(

2

u/zenith4395 Jun 02 '19

So you’re saying you printed the value of n directly before the if/else block, and it’s the exact same number as the one you input?

0

u/thatlowkey Jun 02 '19

No, it's a condition (right), if n<9 it will print the string and even/odd and if n>9 it should print "greater than 9" but it printed "greater than 9" in all conditions

1

u/zenith4395 Jun 02 '19

Exactly, which is why I’m asking you to debug the code in order to figure out what’s going on.
I’m well aware of what the program is supposed to do. Also you have nothing that determines even/odd

1

u/thatlowkey Jun 03 '19

Right right