Wrong output and exit code 9

Hello!

I have been trying to solve this challenge for a while now, but every time I run my code, I only get the output: “Where should I start counting?”, and then the program runs until I hit the stop button. Then, in the output, it also says: “Program ended with exit code: 9” What does that mean, and why doesn’t my code work?

I have been looking around on the forum a bit, and while I have picked up a few tips here and there, I haven’t been able to find any solution to my problem. I would be very thankful if I could get some help, I post my code below :slight_smile:

[code]#import <readline/readline.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char * argv[])
{
printf(“Where should I start counting? “);
const char *numStart = readline(NULL); //Takes whetever number the user puts in and stores it in the variable numStart
int i = atoi(numStart); //Converts numStart, as a string, to a integer
printf(”%d\n”, i); //Prints out the number the user puts in (as a decimal since it’s a integer)

for (i; i >= 0; i -= 3) {
    printf("%d\n", i);
    if (i % 5 == 0) {
        printf("Found one!\n");
    }
}
return 0;

}[/code]

Thanks in advance!

Relax, apart from one warning, there is nothing wrong with your code - it works as expected:

Where should I start counting? 64
64
64
61
58
55
Found one!
52
49
46
43
40
Found one!
37
34
31
28
25
Found one!
22
19
16
13
10
Found one!
7
4
1

The obvious question: Did you actually enter a number on the console and hit the return key?

When the program runs, the readline function causes the program to pause and wait for input until you enter a number on the console and hit the return key.

Haha, thank you! It turned out that my console wasn’t active so I couldn’t type in any number, but after the “activation” it worked like a charm! Thanks for your help! :slight_smile:

(And regarding the warning, I googled a bit and solved it by declaring i inside the for loop like so:

for (int i = atoi(numStart); i >= 0; i -= 3))