0

Whenever I introduce int get_int() I get an error message: error: initializer element is not a compile-time constant int x = get_int()I have tried permutations of get_int(0 that have been suggested without success. What am I doing wrong? Example:

#include <cs50.h>
#include <stdio.h>

int main(void)

int x = get_int()
1
  • the first two lines are: #include <cs50.h> #include <stdio.h> Sorry that only "include" showed up in the original post
    – comuter
    Commented Oct 27, 2017 at 21:52

1 Answer 1

0

Simply put, the program isn't properly structured. There are no curly braces here to bracket the main() code. It should have the following structure:

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    // all of the code for main goes between these curly braces.
    int x = get_int()

}

BTW, if you compile this code, you'll get a new error - unused variable x. You'd need to do something with it to get around that warning/error. Maybe a printf statement?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .