Browse Source

refactoring: simplified randomisation in easy_math

main
parent
commit
0cba14b20a
  1. 48
      src/main/quizproject.c
  2. 1
      src/main/quizproject.h

48
src/main/quizproject.c

@ -27,6 +27,24 @@ int* randomNumber() {
return arr; return arr;
} }
int* randomNumber1() {
srand(time(NULL));
int k = 0, p;
static int arr[32];
while(k<32){
int num =rand()%32;
for (p = 0; p < k; p++){
if(arr[p]==num){
break;
}
}
if(p==k){
arr[k++]=num;
}
}
return arr;
}
//------------Math_quiz_begin------------ //------------Math_quiz_begin------------
@ -115,20 +133,7 @@ void math_choose_question(int num1) {
}; };
srand(time(NULL));
int k = 0, p;
static int arr[32];
while(k<32) {
int num = rand() % 32;
for (p = 0; p < k; p++) {
if (arr[p] == num) {
break;
}
}
if (p == k) {
arr[k++] = num;
}
}
int* arr = randomNumber1();
int num2 = arr[num1]; int num2 = arr[num1];
printf("%s", choose[num2]); printf("%s", choose[num2]);
@ -170,20 +175,7 @@ int math_answer(int num1) {
80, 80,
10 10
}; };
srand(time(NULL));
int k = 0, p;
static int arr[32];
while(k<32) {
int num = rand() % 32;
for (p = 0; p < k; p++) {
if (arr[p] == num) {
break;
}
}
if (p == k) {
arr[k++] = num;
}
}
int* arr = randomNumber1();
int num2 = arr[num1]; int num2 = arr[num1];
return ans[num2]; return ans[num2];

1
src/main/quizproject.h

@ -151,6 +151,7 @@ void math_quiz_option();
void math_solution(char [][10], int); void math_solution(char [][10], int);
void goodbye_message(); void goodbye_message();
void final_score(); void final_score();
int* randomNumber1();
//-------brain_whiz_header_end------------- //-------brain_whiz_header_end-------------

Loading…
Cancel
Save