/***************************************************\
* 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;
}

thing's work fine but at the end of this code i write else if statement to exit the program when user press esc key but when user press that key nothing's happen !!!! what's my mistake ??? i write this code in visual studio 2013.

You need to read on = v. ==... One is to assign a value from the right hand side to the left hand side, and the other is to compare.

Two things to be modified.
1. char ch = _getch(); //This ensures escape key is detected.
2. if and else operators should be used with == instead of =.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.