一些强制用户输入选择的代码
Some code to force a user to enter a choice
我对c++很陌生,我需要一些代码来强迫用户做出选择。第一个选择回调主函数,第二个选择调用return 0
,否则程序在任何选择时都不会在主函数中调用return 0
。选择Y
或y
表示"是",n
或N
表示"否",除了这些字母外,代码不接受任何字母。如果您能帮助我,我将不胜感激,谢谢。
#include "person. h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
person persons;
persons. getInfo();
persons.showInfo();
cout << "do you want to continue, type Y or y for yes and n or N for no to exit" << endl;
char choice;
cin >> choice;
if (choice == ("Y"||"y"))
{
int main();
}
if (choice == ("N"||"n"))
{
return 0;
}
else
{
cout << "please make a choice"; cin >> choice;
} /* This is where I would like to iterate in other for the user to make one of the choices provided above */
return 0;
}
你可以这样写:
if(choice == "Y" || choice == "y")
int main();
else
return 0;
所以他们必须输入Y或Y来继续,然后其他任何东西都会用return 0;
相关文章:
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- c++ Visual Studio 2015 快捷方式,用于从选择代码中生成功能
- 为什么这个模板代码不选择部分专业化
- 有选择地禁用库中的死代码消除
- 我的代码在第 4 个选择后停止工作
- 我的选择排序代码是否存在导致它跳过数组中的元素的问题?
- Tensorflow C++ 代码 SessionFactory::GetFactory 如何选择使用哪个会话?直接会话
- 如何使用选择正确检测我是在Windows还是Linux中构建C 代码
- 我如何使一行代码可以选择,但在已经选择过一次后不重新选择
- 选择一些用灰色代码编码的数字
- 我将如何选择进行多个数学问题,而无需每次复制和粘贴代码
- 有没有修复我的代码没有将 int 声明为我在 if else 循环中选择的内容
- C ,代码::块,我应该在Windows和MacOS中选择哪种项目类型
- 我可以在代码库中有选择地禁用RTTI以减少二进制尺寸
- 当未选择 /CLR时,编译的MATLAB代码崩溃
- 如何修改此基于MFC的代码片段以使用自己选择的窗口类名
- 如何在以下小 c++ 代码中再次为用户提供选择
- 代码无法选择声明的宏
- COM 代码库位置 - 如何选择要使用的版本
- 如何编写用于选择函数的样板代码