switch 不使用 break 语句:#include stdio.h int main(){ int iResponse = 0; printf(\\n1\\tSports\\n);
编程学习网为您整理以下代码实例,主要实现:使用switch结构从菜单评估用户的响应,希望可以帮到各位朋友。
switch 不使用 break 语句:
#include <stdio.h>
int main()
{
int iResponse = 0;
printf("\n1\tSports\n");
printf("2\tGeography\n");
printf("3\tMusic\n");
printf("4\tWorld Events\n");
printf("\nPlease select a category (1-4): ");
scanf("%d", &iResponse);
switch (iResponse) {
case 1:
printf("\nYou selected sports questions\n");
case 2:
printf("You selected geography questions\n");
case 3:
printf("You selected music questions\n");
case 4:
printf("You selected world event questions\n");
} //end switch
}
switch 使用 break 语句:
#include <stdio.h>
int main()
{
int iResponse = 0;
printf("\n1\tSports\n");
printf("2\tGeography\n");
printf("3\tMusic\n");
printf("4\tWorld Events\n");
printf("\nPlease select a category (1-4): ");
scanf("%d", &iResponse);
switch (iResponse) {
case 1:
printf("\nYou selected sports questions\n");
break;
case 2:
printf("You selected geography questions\n");
break;
case 3:
printf("You selected music questions\n");
break;
case 4:
printf("You selected world event questions\n");
} //end switch
}
沃梦达教程
本文标题为:使用switch结构从菜单评估用户的响应


猜你喜欢
- 运算符优先级 1970-01-01
- C语言求模 1970-01-01
- 使用最流行的转义序列 1970-01-01
- “纯虚函数调用"在哪里?崩溃从何而来? 2022-10-18
- C++浮点常数 1970-01-01
- 使用来自float.h和limits的数据,找到该系统的一些 1970-01-01
- 打印扩展的ASCII字符 1970-01-01
- C语言可使用的所有转义序列 1970-01-01
- C++指向数组的指针 1970-01-01
- 使用整数值初始化char类型的变量 1970-01-01