ccompiler-errorscs50initializer

'Initializer element is not a compile-time constant' when assigning a variable


I'm trying to run this code but on the terminal it says 'initializer element is not a compile-time constant:

enter image description here

#include <cs50.h>
#include <stdio.h>
int main(void)
int i = get_int ('first population: ')
int j = get_int ('second population: ')

Solution

  • Your code is wrong. Read closely the early chapters of your learning material.

    You want this:

    #include <cs50.h>
    #include <stdio.h>
    
    int main(void)
    {
      int i = get_int ("first population: ");
      int j = get_int ("second population: ");
      ...
      more code
      ...
    }