include <stdio.h>
include <stdlib.h>
include <time.h>
/*
getchar();从终端接收一个字符
注意:当上一次有输入的情况下 必须要将上一次缓冲区
里面的内容清空
scanf("%d");
123\n;
\n
方式一:
getchar(); //拿走\n
getchar();
方式二:
fflush(stdin);//刷新输入流
return; 结束当前这个函数/方法
exit()导入头文件<stdlib.h> 直接退出程序
main(){
1
2
3
}
add(){
retrun;
}
for(){
switch(){
return 1;
exit();
break;
}
}
/
/int main(){
int old = 123;//原始密码
int input;//输入密码
int wrongTime = 3; //错误次数
printf("**********************\n");
printf(" 欢迎使用建设银行系统\n");
printf("**********************\n");
//int i = 1;
printf("请输入密码:");
for(int i = 1;i <= wrongTime; i++){
scanf("%d", &input);
//判断密码
if(input == old){
//密码正确
break;
}
if(i == wrongTime){
printf("错误次数过多!\n");
return 1;
}
//密码不正确
printf("密码不正确,请重新输入密码:");
}
//接收用户选择
int choice;
char goon;
for(; 1 < 2;){
//主界面
printf("*****************************\n");
printf("1.存款\n");
printf("2.取款\n");
printf("3.查询\n");
printf("4.更改密码\n");
printf("5.退出\n");
printf("*****************************\n");
//提示用户选择
printf("请选择操作:");
scanf("%d", &choice);
//判断操作
switch(choice){
case 1: //存款
int temp;
int total;
printf("请输入存款金额:");
scanf("%d", &temp);
total += temp;
//total = total + temp;
printf("存款成功!可用余额为:%d\n",total);
break;
case 2: //取款
int temp2;
for(;1<2;){
printf("输入取款金额:");
scanf("%d", &temp2);
if(temp2 > total){
printf("余额不足 ");
}else{
total -= temp2;
printf("取款成功 余额为%d\n",total);
break;
}
}
break;
case 3: //查询余额
printf("当前余额为:%d\n",total);
break;
case 4: //更改密码
break;
default://退出
exit(EXIT_SUCCESS);
//exit(EXIT_FAILURE);
break;
}
//提示是否继续
for(;1<2;){
printf("是否继续(y/n):");
getchar();
scanf("%c", &goon);
if(goon == 'y'){
break;
}
if (goon == 'n'){
exit(EXIT_SUCCESS);
}
printf("输入无效 ");
}
}
return 0;
}/
/
main函数:不写实际代码,逻辑
while(1){
int result = checkPassword();
if(result == 0)
{
exit
}/
/
include<stdio.h>
include<stdlib.h>
include<windows.h>
int main(){
printf("1\n");
printf("还有两秒就要消失了哦!");
Sleep(2000);
system("cls");
int a;
scanf("%d",&a);
if(a == 1){printf("恭喜你答对啦!\n");
goto part;
}
if(a != 1){printf("Oh no!你失败了!");
}
part:
int c;
scanf("%d",&c);
printf("1 2\n");
printf("还有两秒就要消失了哦!");
Sleep(2000);
system("cls");
int b[2]{1,2};
if(c == b){
int i;
for( i = 0;i < 2;i++){
printf("%d",b[i]);
}
}
else if(c != b){printf("Oh no!你失败了!");
}
return 0;
}*/
/*
当程序运行起来,系统自动产生一个种子
使用rand产生随机数之后
重新启动程序 再次使用rand发现种子是一样的
总结:只要种子一样 产生的随机数就一样 1 2 3
如果需要每次重新运行都产生不一样的随机数
就需要更改种子
时间:1000 1001 1030
srand(time(NULL)) 导入头文件<stdlib.h> <time.h>
*/
//不保存产生的随机数
//生产随机数和判断的时候种子一样 用rand
//
int main(){
srand(time(NULL));
for(int i = 0;i < 4;i++){
int temp = rand()%9 + 1;
printf("%d",temp);
}
printf("\n");
srand(time(NULL));
for(int i = 0;i<4;i++){
scanf("%d",&a);
int temp = rand() %9 + 1;
printf("%d",temp);
}
return 0;
}