gpt4 book ai didi

C++: 程序 "Not Responding"执行时

转载 作者:行者123 更新时间:2023-11-28 01:33:26 26 4
gpt4 key购买 nike

我正在做这个 C++ 家庭作业,当我尝试执行时,.exe 文件一直显示“无响应”。我关闭了程序和代码块。当我试图打开另一个我知道可以重新开始我的任务并重试的程序时,Codeblocks 停止了工作。现在,当我尝试打开它时,它一直显示“无响应”。

程序应该为用户掷 2 个骰子,用户决定是否要保留骰子数量,一旦用户完成最后一次掷骰,它应该将用户的最终掷骰总数与计算机的总掷骰数 -- 较高者获胜。

我的程序没有返回任何错误...但是在尝试执行时它不会工作...现在我担心我有一个损坏的文件或导致 Codeblocks 停止工作的东西。知道发生了什么以及如何让 Codeblocks 再次正常运行吗?

程序如下:

#include <iostream>
#include <cstdio>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main()
{
srand(time(0));

int Roll1, Roll2, UserRoll, Roll3, Roll4, ComputerRoll;
char Hold;
char PlayAgain;

do
{
Roll1 = 1+(rand()%6);
Roll2 = 1+(rand()%6);
UserRoll = Roll1 + Roll2;

do
{
cout << "Beat the computer!" << endl;
cout << "" << endl;
cout << "You rolled a " << Roll1 << " and a " << Roll2 << "(total= " << UserRoll << ")" << endl;
cout << "" << endl;
cout << "Do you want to keep those? (Y/N): " << endl;
cin >> Hold;

if (Hold == 'N')
{
cout << "Rolling again! " << endl;
}
} while (Hold == 'N');

if (Hold == 'Y')
{
cout << "You chose to keep your numbers. Your total is: " << UserRoll << endl;
} break;

} while (true);

do
{
Roll3 = 1+(rand()%6);
Roll4 = 1+(rand()%6);
ComputerRoll = Roll3 + Roll4;

do
{
cout << "" << endl;
cout << "The computer rolled a " << Roll3 << " and a " << Roll4 << endl;
cout << "" << endl;
cout << "(total= " << ComputerRoll << ")" << endl;

if (ComputerRoll < UserRoll)
{
cout << "Congratulations, you win! " << endl;
}
break;

if (ComputerRoll > UserRoll)
{
cout << "Sorry, you lose. " << endl;
}
break;

if (ComputerRoll == UserRoll)
{
cout << "You tied. " << endl;
}
break;
} while (true);
} while (true);
return 0;

最佳答案

它是“无响应”,因为你的程序是一个死循环:

do
{
do
{
...
break; //exit this inner loop
} while(true);
// will continue here
} while(true); // no way to get out!

关于C++: 程序 "Not Responding"执行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50546576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com