ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用switch实现多选

2021-10-29 11:01:35  阅读:214  来源: 互联网

标签:quit notice newline 多选 实现 comfort Please switch report


代码:

// File name:           Multi_select_Switch
// Last modified Date:  2021年10月29日10点42分
// Last Version:        V1.0
// Descriptions:        使用switch语句实现多选

#include <iostream>
using namespace std;

void showmenu(); // function prototypes
void report();
void comfort();

int main()
{
	char choice;
	showmenu();
	cin >> choice;
	while (choice != 'Q' && choice != 'q')
	{
		switch (choice)
		{
		case 'a':
		case 'A': cout << "\a\n";
			break;
		case 'r':
		case 'R': report();
			break;
		case 'l':
		case 'L': cout << "The boss was in all day.\n";
			break;
		case 'c':
		case 'C': comfort();
			break;
		default: cout << "That's not a choice.\n";
		}
		showmenu();
		cin >> choice;
	}
	return 0;
}

void showmenu()
{
	cout << "Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):\n"
		"A(OR a)) o newline R(OR r) report\n"
		"L(OR l) a notice C(OR c) comfort\n"
		"Q(OR q) quit\n";
}
void report()
{
	cout << "It's been an excellent week for business.\n"
		"Sales are up 120%. Expenses are down 35%.\n";
}
void comfort()
{
	cout << "Your employees think you are the finest CEO\n"
		"in the industry. The board of directors think\n"
		"you are the finest CEO in the industry.\n";
}

运行结果:

Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
a

Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
A

Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
R
It's been an excellent week for business.
Sales are up 120%. Expenses are down 35%.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
r
It's been an excellent week for business.
Sales are up 120%. Expenses are down 35%.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
l
The boss was in all day.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
L
The boss was in all day.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
C
Your employees think you are the finest CEO
in the industry. The board of directors think
you are the finest CEO in the industry.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
c
Your employees think you are the finest CEO
in the industry. The board of directors think
you are the finest CEO in the industry.
Please enter A(OR a), R(OR r), L(OR l), C(OR c), or Q(OR q):
A(OR a)) o newline R(OR r) report
L(OR l) a notice C(OR c) comfort
Q(OR q) quit
Q

D:\Prj\C++\C++_Learning\Multi_select_Switch\Debug\Multi_select_Switch.exe (进程 760)已退出,代码为 0。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .

标签:quit,notice,newline,多选,实现,comfort,Please,switch,report
来源: https://blog.csdn.net/weixin_44410704/article/details/121030356

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有