循环和If语句和功能

时间:2015-11-11 21:00:23

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

我不知道如何在我点击“ 或者' 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;
}

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

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