⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whileio.cpp

📁 高永强 全C编程源码 清华大学出版社 2002年六月第一版
💻 CPP
字号:
//这个程序在本书所带软盘中,文件名为WHILEIO.CPP
//这个程序以人-机对话的方式要求用户输入一个回答,
//以便确定程序是否继续执行。这个程序可以作为一个大程序的一部分。

#include <iostream.h>
#include <ctype.h>		//支持将小写字母转换成大写字母的库子程序toupper()

void main(void)
{
	char ans;

	cout << "Do you want to continue?" << endl;
	cout << "Type y to continue, press any other key to stop...";
	cin  >>  ans;		//等待用户的输入

	while (toupper(ans) == 'Y')
	{
		cout << endl << "Do you want to continue?" << endl;//再次请求输入
		cout << "Type y to continue, press any other key to stop...";
		cin  >>  ans;
	}
	cout << endl << "Thank you for use of this program!" << endl;

}

/*下面是这个程序运行后的一个典型输出结果:
Do you want to continue?
Type y to continue, press any other key to stop...y

Do you want to continue?
Type y to continue, press any other key to stop...y

Do you want to continue?
Type y to continue, press any other key to stop...b

Thank you for use of this program!
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -