Head or Tail (20...............)
點樣係C Program 裏整Head or Tail
(答案要隨機的 有時Head對 有時Tail對
有時Head錯 有時Tail錯 )
1 個解答
評分
- 1 十年前最愛解答
這是"估公字"的程式嗎?
如是,程式碼如下︰
#include
#include
#include
int main(){
int input;
int computerchoice;
do{
do{
printf("Guess Head or Tail (0 for Hard, 1 for tail) , input -1 to quit")
scanf( " %d " ,input);
}while((input<2) &&(input > -2));
if (input == -1) exit(0);
else{
srand(time(0)); // initialize random number generator
computerchoice = rand()%2;
if (input == computerchoice) printf("You are correct");
else printf("The answer should be %s " ,(computerchoice==0)? " Head " : " Tail " );
}
} while (true);
return 0;
}
資料來源: 自己
還有問題嗎?立即提問即可得到解答。