449,408 Members | 1,142 Online
Need help? Post your question and get tips & solutions from a community of 449,408 IT Pros & Developers. It's quick & easy.

Generate multiplication tables

5 Replies

 100+ P: 316 for repetition of numbers for multiplication,you may first generate all the random numbers and keep it in array. e.g : for 3 question array size will be3 or 6 depending upon you use one array or two. while storing random numbers check if the new number generated already exists in the array or not. then output questions using numbers from the array. and for the percentage problem,is it giving error or not printing the correct percentage? Feb 13 '07 #2

 P: 96 Sample code is in c....try to implement in c++ once after understanding the c code...and also implement the average result..... Expand|Select|Wrap|Line Numbers #include #include #include void main() {     int i,j,k,input,res,count;     clrscr();     printf("Enter How many u have to work out :");     scanf("%d",&i);     count=0;     do     {         j=(rand()%10);         k=(rand()%10);         res=j*k;         printf("What %d * %d is :",j,k);         scanf("%d",&input);         if(res==input)         {             printf("Right\n");         }         else         {             printf("Wrong the right answer is : %d\n",res);         }         count++;     }while(count<=i);     getch();     return 0; } Feb 13 '07 #3

 100+ P: 316 this code can also repeate questions(logically). one have to precheck if randomly generated numbers are repeated or not.I think repeatition was the main problem not the logic. Sample code is in c....try to implement in c++ once after understanding the c code...and also implement the average result..... #include #include #include void main() { int i,j,k,input,res,count; clrscr(); printf("Enter How many u have to work out :"); scanf("%d",&i); count=0; do { j=(rand()%10); k=(rand()%10); res=j*k; printf("What %d * %d is :",j,k); scanf("%d",&input); if(res==input) { printf("Right\n"); } else { printf("Wrong the right answer is : %d\n",res); } count++; }while(count<=i); getch(); return 0; } Feb 13 '07 #4

 P: 24 Thank you very much I have found out the solution of the problem. Feb 13 '07 #5

 P: 96 Expand|Select|Wrap|Line Numbers #include #include #include #include  void main() {     int i,j[10],j_j[10],k[10],k_k[10],input,res,count,buf;     time_t t;       clrscr();     printf("Enter How many u have to work out :");     buf=0;     scanf("%d",&i);       srand((unsigned) time(&t));     for(count=0;count<10;count++)     {         j[count]=(rand()%10);         k[count]=(rand()%10);     }     for(count=0;count<10;count++)     {         do         {             j[count]=(rand()%10);             k[count]=(rand()%10);             if(j[count] == j_j[count])             {                 if(k[count] == k_k[count])                 {                     buf=1;                     j[count]=6;                     k[count]=7;                 }                 else                 {                     buf=0;                 }             }         }         while(buf);     }     count=0;     do     {         res=(j[count]*k[count]);         printf("What %d * %d is :",j[count],k[count]);         scanf("%d",&input);         if(res==input)         {             printf("Right\n");         }         else         {             printf("Wrong the right answer is : %d\n",res);         }         count++;     }while(count<=(i-1));       for(count=0;count<10;count++)     {         k_k[count]=k[count];         j_j[count]=j[count];     }     printf("Press any key to continue...");     getch();     return 0;     } Above code will reduce the repetion but not completely.... Feb 14 '07 #6