在用c ++调试程序时,我得到一个空白屏幕(I get a blank screen when debugging a program in c++)

编程入门 行业动态 更新时间:2024-10-24 14:21:44
在用c ++调试程序时,我得到一个空白屏幕(I get a blank screen when debugging a program in c++)

现在发生的事情(在编辑代码之后)是每当我键入多个单词时,它就会出现痉挛。 任何修复? 谢谢。 对不起,如果我好像什么都不知道。 昂贵的书籍和没人教我,让我在线阅读教程。 (编辑后的代码如下。)

#include <iostream> #include <string> using namespace std; string qu; int y; int main() { y = 1; while (y == 1) { cout << "Welcome to the magic 8-ball application." <<"\nAsk a yes or no question, and the 8-ball will answer." << "\n"; cin >> qu; cout << "\nProccessing...\nProccessing...\nProccessing..."; cout << "The answer is...: "; int ans = (int)(rand() % 6) + 1; if (ans == 1) cout << "Probably not."; if (ans == 2) cout << "There's a chance."; if (ans == 3) cout << "I don't think so."; if (ans == 4) cout << "Totally!"; if (ans == 5) cout << "Not a chance!"; if (ans == 6) cout << "75% chance."; system("CLS"); cout << "\nWant me to answer another question?" << "(1 = yes, 2 = no.)"; cin >> y; } return 0; }

Now what happens(after editing code) is whenever I type in more than one word, it has spasms. Any fixes? Thanks. Sorry if I seem like I don't know anything. Expensive books and nobody to teach me has me reading tutorials online. (The edited code is below.)

#include <iostream> #include <string> using namespace std; string qu; int y; int main() { y = 1; while (y == 1) { cout << "Welcome to the magic 8-ball application." <<"\nAsk a yes or no question, and the 8-ball will answer." << "\n"; cin >> qu; cout << "\nProccessing...\nProccessing...\nProccessing..."; cout << "The answer is...: "; int ans = (int)(rand() % 6) + 1; if (ans == 1) cout << "Probably not."; if (ans == 2) cout << "There's a chance."; if (ans == 3) cout << "I don't think so."; if (ans == 4) cout << "Totally!"; if (ans == 5) cout << "Not a chance!"; if (ans == 6) cout << "75% chance."; system("CLS"); cout << "\nWant me to answer another question?" << "(1 = yes, 2 = no.)"; cin >> y; } return 0; }

最满意答案

while (y = 1);

应该

while (y == 1)

你有额外的; 并且应该使用== 。

while (y = 1);

should be

while (y == 1)

You have extra ; and should use ==.

更多推荐

本文发布于:2023-08-06 18:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1453795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空白   屏幕   程序   blank   debugging

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!