其他分享
首页 > 其他分享> > 使用switch实现多选

使用switch实现多选

作者:互联网

代码:

// 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