Microsoft C 编译器仅支持该语言 25 年前的版本。限制之一是所有变量都必须在任何其他语句之前声明。因此,将所有变量声明移至函数顶部。
我看到的下一个错误是使用scanf_s
与%c
格式字符串。您必须传递一个指向该变量的指针,并传递要读取的字符数。
scanf_s("%c", &option, 1);
同样,您需要传递一个地址来读取balance
.
您还需要更改 switch 语句,使其仅包含 case。将裸露的说明移到外面。
您阅读的option
行不通的。因为当你检查1
您正在检查 ASCII 代码 1 的字符。更改option
成为一个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();
}