elementar3.c (1203B)
1 /* Exercise 5.34 */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <time.h> 6 7 int main() 8 { 9 int n1, n2; 10 int num, i = 0; 11 12 int correct = 0; 13 14 for(i = 1; i <= 10; i++) { 15 srand( time(NULL) ); 16 17 n1 = 1 + rand() % 9; 18 n2 = 1 + rand() % 9; 19 20 printf("How much is %d times %d?\n", n1, n2); 21 printf("Answer: "); 22 scanf("%d", &num); 23 24 printf("\n"); 25 if(num == n1 * n2) { 26 switch(1 + rand() % 4) { 27 case 1: 28 printf("Very good!"); 29 break; 30 case 2: 31 printf("Excellent!"); 32 break; 33 case 3: 34 printf("Nice work!"); 35 break; 36 case 4: 37 printf("Keep up the good work!"); 38 } 39 ++correct; 40 } 41 else 42 switch(1 + rand() % 4) { 43 case 1: 44 printf("No. Please try again."); 45 break; 46 case 2: 47 printf("Wrong. Try one more."); 48 break; 49 case 3: 50 printf("Don't give up!"); 51 break; 52 case 4: 53 printf("No. Keep trying."); 54 } /* end switch */ 55 56 printf("\n\n"); 57 } /* end for (i) */ 58 59 60 if( (100 * correct) / 10 < 75) 61 printf("Please ask your instructor for extra help\n"); 62 63 printf("Game over!\n"); 64 65 return 0; 66 } /* E0F main */ 67