C中未声明的标识符

Chi*_*bke 0 c visual-studio-2012

我正在尝试在Visual Studio 2012 Express中用C编译一个小型银行程序.它向我显示了几乎所有变量的这个错误"未声明的标识符",这也是"语法错误:缺少';' 在'type'之前."请告诉我正确的语法.谢谢.

#include<stdio.h>
#include<conio.h>
int main()
{
printf("Welcome to skybank\n");
int deposit,withdraw,kbalance;
char option;
printf("Press 1 to deposit cash\n");
printf("Press 2 to Withdraw Cash\n");
printf("Press 3 to Know Your Balance\n");
scanf_s("%c",option);
int decash,wicash;
switch(option)
{
int balance;
printf("Enter your current Balance\n");
scanf_s("%d",&balance);
case 1:
    printf("Enter the amount you want to deposit\n");
    scanf_s("%d",&decash);
    printf("Thank You\n");
    printf("%d have been deposited in your account\n",decash);
    break;
case 2:
    printf("Enter the amount you want to withdraw\n");
    scanf_s("%d",&wicash);
    int wibal;
    wibal=balance-wicash;
    printf("Thank You\n");
    printf("%d have been withdrawed from your account\n",wicash);
    printf("Your balance is %d\n",wibal);
    break;
case 3:
    printf("Your balance is Rs.%d\n",balance);
    break;
default:
    printf("Invalid Input\n");
    break;
}
getchar();
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*nan 5

Microsoft C编译器仅支持该语言的25年版本.其中一个限制是所有变量必须在任何其他语句之前声明.因此,将所有变量声明移到函数的顶部.

接下来的错误,我可以看到的是使用scanf_s%c格式字符串.您必须将指针传递给变量,并传递要读取的字符数.

scanf_s("%c", &option, 1);
Run Code Online (Sandbox Code Playgroud)

同样,你需要传递一个地址来读取balance.

您还需要更改switch语句,以便它只包含案例.将裸指令移到外面.

你的阅读option将无效.因为当您检查1是否正在使用ASCII代码检查字符时1.更改option为a int并使用读取%d.

也许你正在寻找这样的东西:

#include<stdio.h>
#include<conio.h>

int main(void)
{
    int deposit,withdraw,kbalance;
    int option;
    int decash,wicash;
    int balance;
    int wibal;

    printf("Welcome to skybank\n");
    printf("Press 1 to deposit cash\n");
    printf("Press 2 to Withdraw Cash\n");
    printf("Press 3 to Know Your Balance\n");
    scanf_s("%d", &option);
    printf("Enter your current Balance\n");
    scanf_s("%d", &balance);
    switch(option)
    {
        case 1:
            printf("Enter the amount you want to deposit\n");
            scanf_s("%d", &decash);
            printf("Thank You\n");
            printf("%d have been deposited in your account\n", decash);
            break;
        case 2:
            printf("Enter the amount you want to withdraw\n");
            scanf_s("%d", &wicash);
            wibal=balance-wicash;
            printf("Thank You\n");
            printf("%d have been withdrawed from your account\n", wicash);
            printf("Your balance is %d\n", wibal);
            break;
        case 3:
            printf("Your balance is Rs.%d\n", balance);
            break;
        default:
            printf("Invalid Input\n");
            break;
    }
    getchar();
}
Run Code Online (Sandbox Code Playgroud)