为什么要打破;按 ESC 时不起作用?
why break; dosn't work when i press esc?
一切都很好,但在这段代码的末尾,当用户按下esc键时,我会编写else-if语句退出程序,但当用户按下该键时,什么都没有发生!!!!我犯了什么错???我在visualstudio2013中编写了这段代码。
/***************************************************
* This program imagery dice rolling *
* Write by : saeid asaadian *
* Create date : 11 - 14 - 2015 *
* Version : 1.0 *
***************************************************/
#include <iostream>
#include "conio.h"
#include <ctime>
#include <cstdlib>
#define random(x)(rand()%x)
#define randomize()(srand(time(0)))
using namespace std;
int main()
{
cout << "Please press ENTER to roll the dice and press ESC for exit .";
do
{
char ch = getchar();
if (ch = 13)
{
system("cls");
randomize();
switch (random(6) + 1)
{
case 1:
cout << "The dice is 1";
break;
case 2:
cout << "The dice is 2";
break;
case 3:
cout <<"The dice is 3";
break;
case 4:
cout << "The dice is 4";
break;
case 5:
cout << "The dice is 5";
break;
default:
cout << "The dice is 6";
} //end of switch
} //end of if
else
if (ch = 27)
break;
} while (1); //end of do.while
return 0;
}
=
是C++中的赋值,它不检查相等性。
将最后一个if语句更改为if (ch == 27)
。编辑:将它们全部更改为使用==
相关文章:
- 我的神经网络不起作用 [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++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- 为什么要打破;按 ESC 时不起作用?