这个实例很简单,看一下就能明白,至于我已经对C比较熟悉了,为什么还要从这么简单的例子入手,这个需要再详细的说明一下。由于之前学习C的时候,就是急功近利,没有仔细的去品味C中,特别是指针中的一些乐趣,所以我选择从基础再学习一遍,就这样咯。
~~~
#include <stdio.h>
/**
* 实现自动取款机界面的模拟来学习使用switch语句
* switch...case语句的结构
* switch(int类型变量){
* case 1: //如果是1,进行相应的处理
* ....
* break;
* case 2:
* ....
* break;
* default: //可有可无的,表示如果不是上面的所有
* ....
* break;
* }
*/
int main(void)
{
do{
printf("===================================\n");
printf(": Please select the key: :\n");
printf(": 1: Query :\n");
printf(": 2: Credit :\n");
printf(": 3: Debit :\n");
printf(": 4: Return :\n");
printf("===================================\n");
int selected = 0;
scanf("%d",&selected);
switch(selected){
case 1:
printf("===================================\n");
printf(": Your balance is $1000 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 2:
printf("===================================\n");
printf(": Please select credit money :\n");
printf(": 1: $50 :\n");
printf(": 2: $100 :\n");
printf(": 3: return :\n");
printf("===================================\n");
int credit = 0;
scanf("%d",&credit);
switch(credit){
case 1:
printf("===================================\n");
printf(": Your Credit money is $50 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 2:
printf("===================================\n");
printf(": Your Credit money is $100 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 3:
break;
default:
printf("===================================\n");
printf(": Op error!! :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
}
break;
case 3:
printf("===================================\n");
printf(": Please select debit money :\n");
printf(": 1: $50 :\n");
printf(": 2: $100 :\n");
printf(": 3: $500 :\n");
printf(": 4: $1000 :\n");
printf(": 5: return :\n");
printf("===================================\n");
int debit = 0;
scanf("%d",&debit);
switch(debit){
case 1:
printf("===================================\n");
printf(": Your debit money is $50 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 2:
printf("===================================\n");
printf(": Your debit money is $100 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 3:
printf("===================================\n");
printf(": Your debit money is $500 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 4:
printf("===================================\n");
printf(": Your debit money is $1000 :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
case 5:
break;
default:
printf("===================================\n");
printf(": Op error!! :\n");
printf(": Please enter any key to return :\n");
printf("===================================\n");
getch();
break;
}
break;
case 4:
printf("===================================\n");
printf(": Thank you for your using :\n");
printf(": Good Bye :\n");
printf("===================================\n");
return;
default:
return;
}
}while(1);
return 0;
}
~~~
- 前言
- 实例一:HelloWorld
- scanf函数学习
- 实数比较
- sizeof()保留字获取类型的大小
- 自增/自减学习
- C学习if条件判断和for循环
- C实现的九九乘法表
- C实现一个比较简单的猜数游戏
- 使用C模拟ATM练习switch..case用法
- 记录一个班级的成绩练习一维数组
- C数组实现矩阵的转置
- C二维数组练习
- 利用数组求前n个质数
- C实现万年历
- C实现数组中元素的排序
- C实现任意进制数的转化
- C判断一个正整数n的d进制数是否是回文数
- C使用递归实现前N个元素的和
- 钢材切割问题
- 使用指针比较整型数据的大小
- 指向数组的指针
- 寻找指定元素
- 寻找相同元素的指针
- 整数转换成罗马数字
- 字符替换
- 从键盘读入实数
- C实现字符行排版
- C实现字符排列
- C实例--判断一个字符串是否是回文数
- 通讯录的输入输出
- 扑克牌的结构定义
- 使用“结构”统计学生成绩
- 报数游戏
- 模拟社会关系
- 统计文件中字符个数
- C实现两个文件的内容输出到同一个屏幕