解答例
#include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int i, dice1, dice2, out = 0; for( ; out<3; ){ dice1 = rand() % 6 + 1; dice2 = rand() % 6 + 1; printf("Dice: %d %d Result: ", dice1, dice2); if(dice1==dice2) if(dice1==1) printf("Home run!\n"); else if(dice1==2) printf("Three base hit!\n"); else if(dice1==6) printf("Single hit!\n"); else printf("Two base hit!\n!"); else if(dice1+dice2==7) printf("Single hit!\n"); else{ out++; printf("%d Out\n", out); } } return(0); } |