برنامه انداختن تاس با دستور randomize() و random()
این برنامه تا زمانی که کاربر Enter بزنه، شروع به ریختن تصادفی تاس میکنه و عدد اون رو نمایش میده.
//This program can imagery dice rolling.#include#include#define randomize()(srand(time(0)))#define random(x)(rand()%x)#include#includevoid 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< break; case 2: cout< break; case 3: cout< break; case 4: cout< break; case 5: cout< break; default : cout< }//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
+ نوشته شده در شنبه بیست و یکم دی ۱۳۹۲ ساعت 20:25 توسط کامران زرینی
|