0

I am new to programming and I am trying to learn, so I am trying to write something. But there is this error saying: expected ';' BEFORE number constant. Does anyone know why? Thanks. As I said I am new to programming so do not be amazed at my extremly simple code :D

struct Country{
    char name[50];
    char capital[50];
    char statehead[50];
    int pop;
double area;
};

int main(){

    struct Country stat1;
    stat1.area = 78 866.2;
    stat1.pop = 10 560 000;
    strcpy( stat1.name, "Ceska republika");
    strcpy( stat1.capital, "Praha");
    strcpy( stat1.statehead, "MilosZeman");

    printf("%d", stat1.area);

    return 0;
}
  • A beginners C book is urgently needed. You cant code before you learn the basics. – 0___________ Oct 05 '18 at 16:38
  • Possible duplicate of [Why does the C parser not allow spaces between the digits of an integer literal?](https://stackoverflow.com/questions/7696312/why-does-the-c-parser-not-allow-spaces-between-the-digits-of-an-integer-literal) – Joseph Sible-Reinstate Monica Oct 08 '18 at 01:36

1 Answers1

5

The problem is here:

stat1.area = 78 866.2;
stat1.pop = 10 560 000;

Numbers should not contain spaces, so just remove them and the code should compile.

If you are actually writing C++ code (version 14 or later) you may use digit separators (in floating point or integer number literals) to group them such they are nicely readable:

stat1.area = 78'866.2;
stat1.pop = 10'560'000;
Hero Wanders
  • 3,237
  • 1
  • 10
  • 14
  • Oh my god, I did not notice that :D. Many Thanks. – Kapitan B. Oct 05 '18 at 16:30
  • If you think your question has been answered you may accept the answer by clicking on the checkmark next to it. This helps others to see immediately that you're not searching for help at this question anymore. https://stackoverflow.com/help/someone-answers – Hero Wanders Oct 06 '18 at 08:06