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 didn't put ;s at the end of your statements
    • your main function's body is not enclosed within {}
    • Your strings are not enclosed within "".

    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
      ...
    }