一些强制用户输入选择的代码

时间:2016-10-08 22:48:34

标签: c++

我对c ++很陌生,我需要一些代码的帮助来强迫用户做出选择。第一个选择回调主函数,第二个选择调用return 0,否则在任何选择的主函数中程序都不会被假定为return 0。选择是Yy表示是,nN表示否,除了这些字母外,代码不接受任何字母。 如果我收到帮助,我会非常感激,谢谢。

    #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;
 }

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

if(choice == "Y" || choice == "y")
    int main();
else
    return 0;

所以他们必须让Y或y继续,然后其他任何东西都会以return 0;

终止该程序
相关问题