undeclared identifier in C

前端 未结 5 1496
忘掉有多难
忘掉有多难 2021-01-26 04:29

I am trying to compile a small bank program in C in visual studio 2012 express. It shows me this error \"undeclared identifier\" for almost all variables and this one too \"synt

5条回答
  •  被撕碎了的回忆
    2021-01-26 05:00

    Regarding the unidentified variables, try putting all declarations of variables at the top of the main block, something like:

    int main()
    {
        int deposit, withdraw, kbalance, decash, wicash, wibal;
        char option;
        printf("Welcome to skybank\n");
    

    Older variants of C frown upon mixing variable declarations with code. To my knowledge the C standard of Microsoft's C implementation is pre-C99 so perhaps this could be the issue.

    A few other issues that you should look into:

    scanf_s("%c",option); - option should be &option as you are taking a pointer to that variable.

    Also here: case 1:

    You want '1' (as in case '1') instead of plain 1 as it is a char, not an int you want.

    Same for the other case checks.

    With regards to the scanf_s problems, try compiling with warnings, it should have been pointed out by the compiler.

    Finally, you might want to rid your code of the variables you're not using such as kbalance, withdraw and deposit.

提交回复
热议问题