#include<stdio.h>
void main()
{
int password, op, number = 0, count = 1000, n = 0;
printf("please input password:");
scanf("%d", &password);
while (password != 1234);/有三次 输入密码的机会/
{
n++;
if (n == 3)
{
printf("you have input 3,can not input again!\n");
}
printf("password crror!please input again:");
scanf("%d", &password);
}
loop:printf("\nwelcome! please choice one operate:(1,2,3)\n");
printf("1:count\n; 2:get money\n; 3:return\n");
scanf("%d", &op);/输入一种操作/
swith(op);
{
case1:printf("\nyour count is %d\n", count); goto loop;/账户查询/
case2:printf("\nplease input count that you want to get:");
scanf("%d", &number);
if (number > count, number < 0)printf("\nerror");
else { printf("\nnow,you can take money!"); count -= number; }
goto loop;/取款/
case3: break;/返回/
default:printf("\n operate error!");
goto loop;
}
}
case 2 到 case 3之间的语句都要用{} 包括住,case h和数字之间有空格,switch后面不要;
全是笔误基本错误 switch后多了个;,case和后面之要有空格 default写错
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void main()
{
int password, op, number = 0, count = 1000, n = 0;
printf("please input password:");
scanf("%d", &password);
while (password != 1234);
{
n++;
if (n == 3)
{
printf("you have input 3,can not input again!\n");
}
printf("password crror!please input again:");
scanf("%d", &password);
}
loop:printf("\nwelcome! please choice one operate:(1,2,3)\n");
printf("1:count\n; 2:get money\n; 3:return\n");
scanf("%d", &op);
switch(op)
{
case 1:
printf("\nyour count is %d\n", count); goto loop;
case 2:
printf("\nplease input count that you want to get:");
scanf("%d", &number);
if (number > count, number < 0)
printf("\nerror");
else {
printf("\nnow,you can take money!");
count -= number;
}
goto loop;
case 3:
break;
default:
//default:
printf("\n operate error!");
goto loop;
}
}
报的错 应该是unreachable,意思就是多余代码: 你的代码运行不到这里
如果你想让代码循环 不应使用goto 应该用while