[code]#include <stdio.h> #include <readline/readline.h> #include <stdlib.h> // have to have this library for atoi();
int main(int argc, const char * argv[])
{
// Ask for user input
printf(“Where should I start counting?:”);
// Store input in the String
const char *input = readline(NULL);
// Convert string to integer
int i = atoi(input);
// i >= 0 becasue we want to include 0 as well
// i -= 3 deducts by 3 // Same as i = i - 3;
for (i; i >= 0; i -= 3) {
printf("%d\n",i);
// will be true for anything that is divided without reminder i.e == 0 e.g 10 / 5 = 2 (has no reminder)
if (i % 5 == 0 ) {
printf("Found One!\n");
}
}
return 0;
[quote=“andyallen02”]Hey, thanks for this - it’s exactly what I used so good to see it confirmed
I was a bit worried I was doing it wrong as I get an error message on this line of code
The error I get is “Expression result unused” - know why?
Cheers![/quote]
Late reply, but I thought it was worth responding. Those are not “errors” they are “warnings”. Errors are indicated with a RED OCTAGON, while warnings are indicated with a YELLOW TRIANGLE. The reason you see that warning is because you did not initialize i to a value in the parentheses following for. The following two code snippets should not produce any errors:
1.
I’m a beginner too, so if I misspoke, please correct me.