12,952,792 members (35,493 online)
Rate this:
See more:
hi im very new to c and i decided to write this program, can anyone tell me why its not counting down from the number entered to 0?
```#include <stdio.h>

int printloop(int k )
{
int b;
for (b = k; b < 0; b--)
printf("%d\n",b);
}

int main()
{
int c;

scanf("%d",&c);
if( c > '0' && c < '6')

printloop(c);

return 0;
}```
Posted 25-Sep-12 8:14am
Updated 25-Sep-12 8:19am
v2

Rate this:

## Solution 1

`if( c > '0' && c < '6')`

`c` is an integer defined but you compare it with a character '0' & '6'. Remove quotes around 0 & 6
Sergey Alexandrovich Kryukov 25-Sep-12 14:26pm

One bug nailed down, a 5.
--SA
Sandeep Mewara 25-Sep-12 14:29pm

Thanks SA.
Marcus Kramer 25-Sep-12 14:32pm

+5 for the "other" issue.
Sandeep Mewara 25-Sep-12 14:39pm

:)
ridoy 25-Sep-12 15:29pm

+5
Rate this:

## Solution 2

Because in your `for (b = k; b < 0; b--)`, you aren't allowing it to do any work.
The second clause "b<0" indicates that this loop will only run if b < 0.
Since you set b == k which is greater than 0, the loop will not run.
Your solution is `for (b = k; b >= 0; b--)`
Sergey Alexandrovich Kryukov 25-Sep-12 14:26pm

Another bug nailed down, a 5.
--SA
Marcus Kramer 25-Sep-12 14:32pm

That error was simply too common a mistake that rookies make. I've learned a long time ago to always check the for loop args before anything else when someone says the loop isn't doing anything. Thanks.
Sergey Alexandrovich Kryukov 25-Sep-12 17:41pm

Sure...
--SA
Sandeep Mewara 25-Sep-12 14:29pm

5! Marcus!

:)
Marcus Kramer 25-Sep-12 14:32pm

Thanks Sandeep.
flaringdon 25-Sep-12 14:34pm

thanks marcus and sandeep
ridoy 25-Sep-12 15:29pm

+5

Top Experts
Last 24hrsThis month
 OriginalGriff 305 RickZeeland 85 ppolymorphe 80 Member 13197019 77 David_Wimbley 60
 OriginalGriff 6,389 CHill60 3,490 Maciej Los 3,103 Jochen Arndt 1,975 ppolymorphe 1,920