Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.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++ &引用;“边做边做”;循环挂起,不重复_C++_Do While - Fatal编程技术网

C++ &引用;“边做边做”;循环挂起,不重复

C++ &引用;“边做边做”;循环挂起,不重复,c++,do-while,C++,Do While,我遇到了一个do while循环不重复的问题。 当我在提示再次添加两个数字时选择N时,它会按预期退出程序,但选择Y或Y会挂起程序,将我带到下一行,但使我无法键入任何内容。如果你能帮助我,我将不胜感激。谢谢 #include <iostream> using namespace std; int main() { int number1, number2; //Two numbers int sum; //Sum char again; //For

我遇到了一个do while循环不重复的问题。 当我在提示再次添加两个数字时选择N时,它会按预期退出程序,但选择Y或Y会挂起程序,将我带到下一行,但使我无法键入任何内容。如果你能帮助我,我将不胜感激。谢谢

#include <iostream>
using namespace std;
int main()
{

int number1, number2; //Two numbers
int sum;              //Sum
char again;     //For yet another attempt


{  //Inputting the two numbers

    cout << "\nEnter two numbers, and i will add them: ";
    cin >> number1 >> number2;

    //Adding the two numbers

    sum = number1 + number2;
    cout << "The sum of the two numbers you have picked is " << sum << "\n\n";

    //Does the user want to add two other numbers?
    cout << "Do you want to add two other numbers? (Y/N) ";
    cin >> again;
}
    while (again == ('y') || again == ('Y'));


   return 0;
}
#包括
使用名称空间std;
int main()
{
int number1,number2;//两个数字
int sum;//sum
再次char;//再次尝试
{//输入两个数字
cout>number1>>number2;
//把这两个数字相加
总和=数字1+数字2;
库特
当循环语法在上面时,我猜你们在语法上错过了do世界。
试着替换你所做的,而块如下

do{  //Inputting the two numbers

cout << "\nEnter two numbers, and i will add them: ";
cin >> number1 >> number2;

//Adding the two numbers

sum = number1 + number2;
cout << "The sum of the two numbers you have picked is " << sum << "\n\n";

//Does the user want to add two other numbers?
cout << "Do you want to add two other numbers? (Y/N) ";
cin >> again;}while (again == ('y') || again == ('Y'));
do{//输入两个数字
cout>number1>>number2;
//把这两个数字相加
总和=数字1+数字2;

是的,你需要一段时间做一件事。说得再好不过了


每次在运行程序之前向代码或调试中添加新内容时,也要进行生成检查,并检查所有警告或错误(如果有)。此外,还要依靠用于帮助查找小错误的IDE。我们有时都会忘记一些小错误。

谢谢!我真的很惊讶我错过了这些!对不起,我是新手。这是“回答你的问题”按钮吗?对不起,我没有理解你若要接受答案,是否按“回答您的问题”按钮?若要将答案标记为已接受,请单击答案旁边的复选标记,将其从灰色变为已填写。代码是否应阻塞(用于循环)在
while
关键字之后,而不是之前?这是一个正常的while语句。我只是忘记了do部分。编码时需要遵循语法
do{  //Inputting the two numbers

cout << "\nEnter two numbers, and i will add them: ";
cin >> number1 >> number2;

//Adding the two numbers

sum = number1 + number2;
cout << "The sum of the two numbers you have picked is " << sum << "\n\n";

//Does the user want to add two other numbers?
cout << "Do you want to add two other numbers? (Y/N) ";
cin >> again;}while (again == ('y') || again == ('Y'));