c++中的退出特性不起作用
Quit feature in C++ not working
所以我尝试着创造一个能够让玩家在完成游戏后退出游戏的功能,或者让玩家能够选择再次体验游戏。重放选项工作,但每当我尝试退出部分,它只是回到游戏的开始。
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
using namespace std;
int main() {
SetConsoleTitle("Guess the number! | v1.0");
int replay;
replay = 1;
int g, n;
play:
g = NULL;
srand(time(NULL));
n = rand() % 20 + 1;
system("cls");
cout << "Number guessing game" << endl;
cout << "********************" << endl;
cout << endl;
cout << "The random number has been generated. It is between 1 and 20" << endl;
system("pause");
while (g != n) {
system("cls");
cout << "Number Guessing Game" << endl;
cout << "********************" << endl;
cout << endl;
cout << "Type a guess between 1 and 20 then press ENTER" << endl;
cout << "Your guess: ";
cin >> g;
}
if (g = 1113) {
goto debugskip;
}
debugskip:
system("cls");
cout << "You have found the number!" << endl;
cout << "The number was " << n << endl;
cout << "Would you like to play again? 1 for yes, 2 for no.";
cin >> replay;
if (replay = 1) {
goto play;
}
else if (replay = 2) {
exit(1);
}
return 0;
}
在if语句中使用赋值运算符而不是等号运算符
改变if (replay = 1) {
if (replay == 1) {
对于同样的问题在其他地方做同样的事情
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++代码在 Gedit 中有效,但在 VS 中不起作用(它只是打印"按任意键退出......"。消息)
- 尝试退出循环时,Ctrl+Z 不起作用
- c++中的退出特性不起作用