Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ do/while循环不工作_C++_Loops_While Loop - Fatal编程技术网

C++ do/while循环不工作

C++ do/while循环不工作,c++,loops,while-loop,C++,Loops,While Loop,有人能帮我做这个循环吗。当有人输入Y时,当循环询问您是否有其他名称时。它会一直问相同的问题,直到用户输入N char ans; do { cout<<"Do you have another name (Y/N)?\n"; while(ask!="y"!! ans!!="n") { cout<<"you must enter 'Y' or an 'N'.\n"; cin >> ans; } if(ans=='y')

有人能帮我做这个循环吗。当有人输入Y时,当循环询问您是否有其他名称时。它会一直问相同的问题,直到用户输入N

char ans;

do {
cout<<"Do you have another name (Y/N)?\n";


while(ask!="y"!! ans!!="n") {
      cout<<"you must enter 'Y' or an 'N'.\n";  
      cin >> ans; 
}

if(ans=='y')
    enter other name();
elseif  end;

这很简单,也很简单:

string answer;
do {
    enter_other_name();
    cout << "Do you have another name (Y/N)" << endl;
    cin >> answer;
} while(answer!="n");

它将对用户进行bug,直到用户输入n。如果您想在他按y时继续监听,则将最后一行更改为}whileanswer==y

这很简单,也很简单:

string answer;
do {
    enter_other_name();
    cout << "Do you have another name (Y/N)" << endl;
    cin >> answer;
} while(answer!="n");

它将对用户进行bug,直到用户输入n。如果您想在他按y时继续监听,则将最后一行更改为}whileanswer==y

那代码根本没有意义。您有一个未终止的do循环和一个while循环,您正在比较一个char和一个char*,!!=不是有效的运算符

请发布一些编译的代码。当您编译它时,您可能已经了解了问题所在


就张贴示例而言,复制和粘贴是你的朋友。

这段代码根本没有意义。您有一个未终止的do循环和一个while循环,您正在比较一个char和一个char*,!!=不是有效的运算符

请发布一些编译的代码。当您编译它时,您可能已经了解了问题所在


就张贴示例而言,复制和粘贴是你的朋友。

下次,请投入足够的努力,至少使其编译,然后在你认为需要更改的行上添加注释。现在你已经有了可怕的语法错误。下次,投入足够的精力至少让它编译,然后在你认为需要更改的行上添加注释。现在你有可怕的语法错误。