<> Program function and operation

The design of the program is a digital puzzle game , The purpose is to cultivate the mathematical thinking of children players , Improve players' mathematical ability . There are four different games in the game , They are four operations of one digit , Two digit four arithmetic , Find the best value game , Sorting game . The program can generate random questions , And can check whether the player's answer is correct . For children to feel the fun of the game , A scoring system was specially set up , There are different bonus points for answering different questions correctly , And it will be divided into different groups according to the total score 「 Rank 」, Present to player . in addition , The program also uses a more dynamic design , Let players fall in love with the game .

<> Screenshot of program running

<> Arithmetic game

<> Find the best value game

<> Sorting game

<> Score statistics

<> Code section

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #
include<math.h> int score0 = 0; int u, z;
<> Start up interface and main menu
int main() // Main function Game Description { int menu(); char o; printf("\n\n"); printf("\t= = = = =
= = = = = = = = = = =\n"); printf("\t= number word benefit wisdom Small swim play =\n"); printf("\t= =\n");
printf("\t= Welcome to play the digital puzzle game , The game has =\n"); printf("\t= Four little games , among 『 count 』 There are four small games =\n");
printf("\t= Three levels . When you challenge the more difficult the game , and =\n"); printf("\t= Challenge success , You will get a higher score reward , most =\n");
printf("\t= Your game will be divided according to your total score . =\n"); printf("\t= =\n"); printf("\t= =\n");
printf("\t= * * * * * * * * * =\n"); printf("\t= * swim play paragraph position * =\n"); printf("\t=
* 『 bronze 』 --- 5 branch with lower * =\n"); printf("\t= * 『 silver 』 --- 5 branch - 10 branch * =\n"); printf(
"\t= * 『 gold 』 --- 10 branch - 15 branch * =\n"); printf("\t= * 『 Platinum 』 --- 15 branch - 20 branch * =\n");
printf("\t= * 『 Diamonds 』 --- 20 branch - 25 branch * =\n"); printf("\t= * 『 Starshine 』 --- 25 branch - 30 branch
* =\n"); printf("\t= * 『 The king 』 --- 30 branch with upper * =\n"); printf("\t= * * * * * * * * *
=\n"); printf("\t= =\n"); printf("\t= do person ： Cowjiang =\n"); printf("\t= =\n");
printf("\t= = = = = = = = = = = = = = = =\n\n"); printf("\t Press enter to start the game ");
scanf_s("%c", &o, 1); if (o == '\n') // Enter enter to start the game { system("cls"); menu(); } else
exit(0); } int menu() // Game main menu function { void one_arithmetic(); void two_arithmetic();
void comparation(); void maxmin(); int score(); int scores(); int scorep(); int
o; system("color 30"); printf("\n\n"); printf("\t ** \n"); printf("\t * * \n");
printf("\t * main food single * \n"); printf("\t * * \n"); printf("\t* * * * * * * * * * *
* * * * \n"); printf("\t * * \n"); printf("\t * 1.『 count 』 One digit operation * \n"); printf("\t
* 2.『 count 』 Two digit operation * \n"); printf("\t * 3.『 look for 』 Find the best value between cracks * \n"); printf("\t * 4.『 Row
』 Sort ratio size * \n"); printf("\t * 5. I Of order front have to branch * \n"); printf("\t * 6. retreat Out benefit wisdom swim play
* \n"); printf("\t * * \n"); printf("\t * * * * * * * * * \n\n"); printf("\t
Please input serial number to select ："); scanf_s("%d", &o); if (o == 1) { one_arithmetic(); } else if (o == 2
) { two_arithmetic(); } else if (o == 3) { maxmin(); } else if (o == 4) {
comparation(); } else if (o == 5) { scorep(); } else if (o == 6) { printf(
"\n\t\t= = = = = = = = = = = = = = = = =\n"); printf("\t\t= =\n"); printf(
"\t\t= Thank you for your visit ! =\n"); printf("\t\t= =\n"); printf("\t\t= = = = = = = = = = = =
= = = = =\n"); exit(0); } else { printf("\n\t Oh, your serial number is wrong , Please select again !\n"); system(
<> Score statistics
int scorep() // View current score { system("color F4"); z = score0; system("cls"); printf(
"\n\n"); printf("\t\t * \n"); printf("\t\t * * \n"); printf("\t\t * * \n");
printf("\t\t* * * * * * * * \n"); printf("\t\t * Current score ： * \n"); printf("\t\t *
%2d branch * \n", z); printf("\t\t * * * * \n"); printf("\t\t * * * * \n"); if (z <= 5
) { printf("\t\t ** [ young copper ] ** \n"); printf("\t\t * * \n"); } else if (z > 5 && z
<= 10) { printf("\t\t ** [ white silver ] ** \n"); printf("\t\t * * \n"); } else if (z > 10
&& z <= 15) { printf("\t\t ** [ yellow gold ] ** \n"); printf("\t\t * * \n"); } else if (z
> 15 && z <= 20) { printf("\t\t ** [ platinum gold ] ** \n"); printf("\t\t * * \n"); } else
if (z > 20 && z <= 25) { printf("\t\t ** [ drill stone ] ** \n"); printf("\t\t * * \n"); }
else if (z > 25 && z <= 30) { printf("\t\t ** [ Star Glory ] ** \n"); printf("\t\t * *
\n"); } else if (z > 30) { printf("\t\t ** [ king person ] ** \n"); printf("\t\t * * \n");
} printf("\n\n\t Please input to continue the game 1, Please enter to exit the game 2 ："); scanf_s("%d", &u); if (u == 1) // Return to main menu {
system("cls"); menu(); } else if (u == 2) // Quit the game { printf("\n\t\t= = = = = = =
= = = = = = = = = =\n"); printf("\t\t= =\n"); printf("\t\t= Thank you for your visit ! =\n");
printf("\t\t= =\n"); printf("\t\t= = = = = = = = = = = = = = = = =\n"); exit(0);
score0++; return score0; } int scores() // Subtraction function { score0--; return score0; }
<> One digit operation
void one_arithmetic() // One digit operation { int p, a, b, c, d, f, g, h, l, m; float e;
srand(time(NULL)); a = rand() % 10; b = rand() % 10; g = rand() % 10; h = rand()
% 10; system("color E0"); system("cls"); printf("\n\n\t\t * * * * * * * * \n");
// One digit operation main menu printf("\t\t * * \n"); printf("\t\t * 1. [ First pass ] plus method * \n"); printf(
"\t\t * 2. [ Second level ] reduce method * \n"); printf("\t\t * 3. [ The third pass ] ride method * \n"); printf("\t\t *
4. [ The fourth level ] except method * \n"); printf("\t\t * 5. [ Advanced ] Hybrid operation * \n"); printf("\t\t * 6. [ return return ]
Main menu * \n"); printf("\t\t * * \n"); printf("\t\t * * * * * * * * \n"); printf(
"\t\t * * * \n"); printf("\t\t * * * \n"); printf("\t\t * * * * * \n"); printf(
"\t\t * * * \n"); printf("\t\t * \n"); printf("\t\t Please enter the number to select the challenge level ："); scanf_s(
"%d", &p); while (p == 1) // One digit addition { system("cls"); printf("\n\t%d + %d = ", a, b
); scanf_s("%d", &c); if (c == a + b) { system("color AE"); printf(
"\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (c != a + b) {
system("color 4E"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); }
one_arithmetic(); } while (p == 2) // One digit subtraction { system("cls"); if (a > b) // Control large number minus decimal
{ printf("\n\t%d - %d = ", a, b); scanf_s("%d", &c); if (c == a - b) { system(
"color AE"); printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else
if (c != a - b) { system("color 4E"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system(
"pause"); } one_arithmetic(); } else if (a < b) { system("cls"); printf("\n\t%d
- %d = ", b, a); scanf_s("%d", &c); if (c == b - a) { system("color AE"); printf
("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (c != b - a) {
system("color 4E"); printf("\n\t What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); }
one_arithmetic(); } } while (p == 3) // One digit multiplication { system("cls"); printf("\n\t%d *
%d = ", a, b); scanf_s("%d", &c); if (c == a * b) { system("color AE"); printf(
"\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (c != a * b) {
system("color 4E"); printf("\n\t\t What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); }
one_arithmetic(); } while (p == 4) // One digit Division { system("cls"); b = rand() % (9) + 1
; // Prevent divisor from being 0 printf("\n\t（ Round to retain integers ）%d divide %d be equal to ", a, b); scanf_s("%f", &e); f = b / 2
; // rounding if (a % b <= f) { d = (int)(e); if (d == a / b) { system("color AE");
printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (d != a / b
) { system("color 4E"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } }
if (a % b > f) { d = (int)(e - 0.5); if (d == a / b) { system("color AE");
printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (d != a / b
) { system("color 4E"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } }
one_arithmetic(); } while (p == 5) // One digit mixed operation { system("cls"); printf("\n\t%d +
%d * ( %d - %d ) = ", a, b, g, h); scanf_s("%d", &l); m = a + b * (g - h); if (l
== m) { system("color AE"); printf("\n fantastic ! Challenge success , plus 2 branch !\n\n"); score(); score();
system("pause"); } else if (l != m) { system("color 4E"); printf(
"\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } one_arithmetic(); } while (p == 6)
{ system("cls"); menu(); } while (p < 1 || p > 6) { system("color 4E"); printf(
"\n\t\t Wrong number input , Please re-enter !\n\n"); system("pause"); one_arithmetic(); } }
<> Two digit operation
void two_arithmetic() // Two digit operation { int p, a, b, c, d, f, g, h, l, m; float e;
srand(time(NULL)); a = rand() % (90) + 10; b = rand() % (90) + 10; g = rand() %
(90) + 10; h = rand() % (90) + 10; system("color B0"); system("cls"); printf(
"\n\n\t\t * * * * * * * * \n"); // Two digit operation main menu printf("\t\t * * \n"); printf("\t\t
* 1. [ First pass ] plus method * \n"); printf("\t\t * 2. [ Second level ] reduce method * \n"); printf("\t\t * 3.
[ The third pass ] ride method * \n"); printf("\t\t * 4. [ The fourth level ] except method * \n"); printf("\t\t * 5.
[ Advanced ] Hybrid operation * \n"); printf("\t\t * 6. [ return return ] Main menu * \n"); printf("\t\t * * \n");
printf("\t\t * * * * * * * * \n"); printf("\t\t * * * \n"); printf("\t\t * * *
\n"); printf("\t\t * * * * * \n"); printf("\t\t * * * \n"); printf("\t\t * \n");
printf("\t\t Please enter the number to select the challenge level ："); scanf_s("%d", &p); while (p == 1) // Two-digit Addition { system
("cls"); printf("\n\t%d + %d = ", a, b); scanf_s("%d", &c); if (c == a + b) {
system("color AE"); printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); }
else if (c != a + b) { system("color 4B"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n");
system("pause"); } two_arithmetic(); } while (p == 2) // Two-digit Subtraction { if (a > b)
// Control large number minus decimal { system("cls"); printf("\n\t%d - %d = ", a, b); scanf_s("%d", &c); if
(c == a - b) { system("color AE"); printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score();
system("pause"); } else if (c != a - b) { system("color 4B"); printf(
"\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } two_arithmetic(); } else if (a < b
) { system("cls"); printf("\n\t%d - %d = ", b, a); scanf_s("%d", &c); if (c == b
- a) { system("color AE"); printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system(
"pause"); } else if (c != b - a) { system("color 4B"); printf(
"\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } two_arithmetic(); } } while (p ==
3) // Two digit multiplication { system("cls"); printf("\n\t%d * %d = ", a, b); scanf_s("%d", &c);
if (c == a * b) { system("color AE"); printf("\n fantastic ! Challenge success , plus 1 branch !\n\n"); score();
system("pause"); } else if (c != a * b) { system("color 4B"); printf(
"\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } two_arithmetic(); } while (p == 4)
// Two digit Division { b = rand() % (9) + 1; // Prevent divisor from being 0 system("cls"); printf(
"\n\t（ Round to retain integers ）%d divide %d be equal to ", a, b); scanf_s("%f", &e); f = b / 2; // rounding if (a % b
<= f) { d = (int)(e); if (d == a / b) { system("color AE"); printf(
"\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (d != a / b) {
system("color 4B"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } } if (a
% b > f) { d = (int)(e - 0.5); if (d == a / b) { system("color AE"); printf(
"\n fantastic ! Challenge success , plus 1 branch !\n\n"); score(); system("pause"); } else if (d != a / b) {
system("color 4B"); printf("\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } }
two_arithmetic(); } while (p == 5) // Two digit mixed operation { system("cls"); printf("\n\t%d +
%d * ( %d - %d ) = ", a, b, g, h); scanf_s("%d", &l); m = a + b * (g - h); if (l
== m) { system("color AE"); printf("\n fantastic ! Challenge success , plus 2 branch !\n\n"); score(); score();
system("pause"); } else if (l != m) { system("color 4B"); printf(
"\n What a pity ! The challenge failed , Don't lose heart !\n\n"); system("pause"); } one_arithmetic(); } while (p == 6)
{ system("cls"); menu(); } while (p < 1 || p > 6) { system("color 4B"); printf(
"\n\t\t Wrong number input , Please re-enter !\n\n"); system("pause"); two_arithmetic(); } }
<> Sorting game
void comparation() // Sorting game { int a, b; int i, j, n, p, q; srand(time(NULL)
); for (i = 0; i < 5; i++) a[i] = rand() % 10; system("cls"); system("color 9F")
; printf("\n\n\t* * * * * * * * * * * * * *\n"); // Rules of the sorting game printf("\t* swim play gauge be
*\n"); printf("\t* Five random integers will be displayed at the beginning of the game , *\n"); printf("\t* Please input the sorted data from small to large according to the prompt *\n");
printf("\t* Five integers of , If the order is correct, you can get it 3 *\n"); printf("\t* Bonus points . Come on , You can do it ! *\n"); printf(
"\t* * * * * * * * * * * * * *\n"); printf("\t * * * \n"); printf("\t * * * \n")
; printf("\t * * * * * \n"); printf("\t * * * \n"); printf("\t * \n"); printf(
"\t Enter the number 0 You can start the game ："); scanf_s("%d", &p); if (p == 0) printf("\n\n\t* * * * * *
* * * * * * * *\n"); printf("\t* *\n"); printf("\t* "); for (i = 0; i < 5; i++)
printf(" %d ", a[i]); for (j = 0; j < 4; j++) // Arrange arrays from small to large { for (i = 0; i < 4 -
j; i++) { if (a[i] > a[i + 1]) { n = a[i]; a[i] = a[i + 1]; a[i + 1] = n; } } }
printf(" *\n"); printf("\t* *\n"); printf("\t* * * * * * * * * * * * * *\n\n");
printf(" next , Please enter the sorted five integers from small to large （ Space off ）："); for (i = 0; i < 5; i++) scanf_s("%d", &b[
i]); for (i = 0; i < 5; i++) // Verify the answer is correct { if (a[i] == b[i]) continue; else {
system("color 49"); printf("\n\t What a pity , Almost succeeded ! Challenge again !\n\n"); system("pause");
comparation(); } } system("color AF"); printf("\n Wow, you're great , Challenge success ! get 3 Bonus points !\n\n");
score(); score(); score(); system("pause"); system("color 0F"); printf(
"\n\n Want to challenge other games ?\n\n"); printf("1. Challenge other games "); printf(" 2. Continue to challenge the sorting game "); printf("
3. View current score \n\n"); printf(" Reply to the number serial number and choose one ："); scanf_s("%d", &q); if (q == 2) { system
("cls"); comparation(); } else if (q == 3) scorep(); else { system("cls"); menu(
); } } else // Exit sort game ? { system("color F0"); printf("\n\n Want to play another game ?\n\n"); printf(
"1. Challenge other games "); printf(" 2. Continue the current game \n\n"); printf(" Reply to the number serial number and choose one ："); scanf_s("%d", &
q); if (q == 2) comparation(); else { system("cls"); menu(); } } }
<> Find the best value game
void maxmin() { int i, j, n, p, q, max, min, maxx, minn; int a; srand(time(
NULL)); system("color DF"); system("cls"); printf("\n\n\t* * * * * * * * * * *
* * *\n"); // Find the most valuable rules of the game printf("\t* swim play gauge be *\n"); printf("\t* Five random integers will be displayed at the beginning of the game ,
*\n"); printf("\t* Please find the maximum and minimum of five integers respectively *\n"); printf("\t* value , If the answer is correct, you can get it 2 Bonus points . *\n");
printf("\t* Come on , You can do it ! *\n"); printf("\t* * * * * * * * * * * * * *\n"); printf(
"\t * * * \n"); printf("\t * * * \n"); printf("\t * * * * * \n"); printf("\t *
* * \n"); printf("\t * \n"); printf("\t Enter the number 0 You can start the game ："); scanf_s("%d", &p); if
(p == 0) { for (i = 0; i < 5; i++) a[i] = rand() % 10; printf("\n\n\t* * * * *
* * * * * * * * *\n"); printf("\t* *\n"); printf("\t* "); for (i = 0; i < 5; i++
) printf(" %d ", a[i]); printf(" *\n"); printf("\t* *\n"); printf("\t* * * * *
* * * * * * * * *\n\n"); printf(" next , Please find the maximum value ："); scanf_s("%d", &maxx); printf(
"\n Then please find the minimum value ："); scanf_s("%d", &minn); max = a; min = a; for (i = 0; i < 5;
i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } if (maxx ==
max&& minn == min) // Verify the answer is correct { system("color AF"); printf("\n Wow, you're great ! Get a reward 2
branch !\n\n"); score(); score(); system("pause"); system("color 0F"); printf(
"\n\n Want to challenge other games ?\n\n"); printf("1. Challenge other games "); printf(" 2. Continue to challenge to find the best value game "); printf("
3. View current score \n\n"); printf(" Reply to the number serial number and choose one ："); scanf_s("%d", &q); if (q == 2) { system
("cls"); maxmin(); } else if (q == 3) scorep(); else { system("cls"); menu(); }
} else { system("color 4F"); printf("\n It's a little pity , Challenge again !\n\n"); system("pause");
maxmin(); } } else // Quit the best value game ? { system("color F0"); printf("\n\n Want to play another game ?\n\n");
printf("1. Challenge other games "); printf(" 2. Back to the current game \n\n"); printf(" Reply to the number serial number and choose one ："); scanf_s(
"%d", &q); if (q == 2) maxmin(); else { system("cls"); menu(); } } }
<> Summary

This digital puzzle game is the first time I've written one of this scale C
Language program , Limited knowledge , It took a lot of time to write this program , There may be imperfections in the code , It doesn't simplify the code as much as possible . last , You are welcome to give me some suggestions , Let's study together , Common progress , awesome !

Technology
Daily Recommendation