برنامه انداختن تاس با دستور randomize() و random()
این برنامه تا زمانی که کاربر Enter بزنه، شروع به ریختن تصادفی تاس میکنه و عدد اون رو نمایش میده.
//This program can imagery dice rolling.
#include
#include
#define randomize()(srand(time(0)))
#define random(x)(rand()%x)
#include
#include
void main()
{
cout<<"Press Enter for roll the dice and press Esc for exit.";
int n=1;
do{
char ch=getch();
if(ch==13)
{
clrscr();
randomize();
switch(random(6)+1)
{
case 1:
cout<
case 2:
cout<
case 3:
cout<
case 4:
cout<
case 5:
cout<
default :
cout<
}//end of if
else if(ch==27)
break;//break the loop if user press the Esc.
}while(1);//end of DO…WHILE loop.
}
//end
نظرات شما عزیزان: