/***************************************************\
* 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;
}
答案 0 :(得分:2)
=
是C ++中的赋值,它不检查相等性。
将您的最后一句if语句更改为if (ch == 27)
。
编辑:将所有这些更改为使用==