برنامه انداختن تاس با دستور randomize() و random()
برنامه انداختن تاس با دستور randomize() و random()
این برنامه تا زمانی که کاربر Enter بزنه، شروع به ریختن تصادفی تاس میکنه و عدد اون رو نمایش میده.
برنامه انداختن تاس با دستور randomize() و random()
این برنامه تا زمانی که کاربر Enter بزنه، شروع به ریختن تصادفی تاس میکنه و عدد اون رو نمایش میده.
PHP:
//This program can imagery dice rolling.
#include <stdlib.h>
#include <time.h>
#define randomize()(srand(time(0)))
#define random(x)(rand()%x)
#include <conio.h>
#include <iostream.h>
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<<n++<<"- The dice is 1.";
break;
case 2:
cout<<n++<<"- The dice is 2.";
break;
case 3:
cout<<n++<<"- The dice is 3.";
break;
case 4:
cout<<n++<<"- The dice is 4.";
break;
case 5:
cout<<n++<<"- The dice is 5.";
break;
default :
cout<<n++<<"- The dice is 6.";
}//end of switch
}//end of if
else if(ch==27)
break;//break the loop if user press the Esc.
}while(1);//end of DO…WHILE loop.
}
//end