-2

Made a C for-loop, and it doesn't get into it. It just skips it entirely, and I don't know why

int main(void) {
  int N = 5;
  int input;
  scanf("%d", &input);

  int c;
  for(c=0; c==N; c++) {
    srand(time(0));
    int random = rand() % 99;
    printf("Loteria: %d\n", random);
    
    if (input == random) {
      printf("\nAcertou!\n");
    }
  }
  return 0;
}
Jens
  • 69,818
  • 15
  • 125
  • 179
weg
  • 27
  • 3

1 Answers1

1

It appears you misunderstood the for loop termination condition.

The condition part in for ( ; condition ; ) does not specify when to stop, but how long to continue if true. A tiny change of your condition should work:

for (c = 0; c < N; c++) {

This is the idiomatic code to iterate a loop exactly N times.

Jens
  • 69,818
  • 15
  • 125
  • 179