c++ - While 循环和 If 语句和函数

标签 c++ function loops if-statement while-loop

我不知道如何通过仅在我点击“n”或“N”时关闭来无限期地继续循环...一旦我放入任何东西它最终会关闭,那么我该如何回到循环中?

int counter = 5;
while(counter > 1)
linear(xcoordinateone, xcoordinatetwo, ycoordinateone, ycoordinatetwo, slope, intercept); //calling
{
cout<<"The points you entered define the function: y = " << slope << xone << "+" << intercept;
cout << "\n Do you want to continue?";
if (answer == 'N' || answer == 'n');    
    cin >> answer;
    return 0;
}

最佳答案

您可以在 while 循环中使用多个条件:

answer = 'y';
while(answer != 'N' && answer != 'n'){
    cout << "\n Do you want to continue?";
    cin >> answer;
}

关于c++ - While 循环和 If 语句和函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659744/

相关文章:

c++ - std::tuple 与多个空成员的比较不会在 GCC 上编译

c++ - 我如何在不使用 virtual 关键字的情况下覆盖这个 C++ 继承的成员函数?

javascript - 在 JavaScript 中对同一个变量调用多个函数

jquery - 如何清除(删除)jQuery 中所有排队的函数?

java - 如何在android中提取hashmap的arraylist列表并循环遍历它?

c++ - Linux 上的文件描述符 3 有什么特别之处?

c++ - 如何使用默认值将值分配给构造函数中的枚举?

Javascript 函数变量传递语法问题

php - 避免循环查询 - 特定情况

c# - 执行存储过程列表的性能问题