⑴ 用户可以从菜单中选择某种运算进行练习。具体包括:加法,减法,乘法,除法;也可以退出程序.
⑵ 用户可以指定每次练习的题目数量、设置练习的总分;
⑶ 每小题练习后给出结果正确与否的提示;一次练习结束后,给出用户所得的总分;
⑷ 用户选择退出时,可退出系统。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define num 10
void showmain();
int getchoice();
int add();
int sub();
int mul();
int div();
void prnscore();
void exit();
//退出系统
void exit()
{
printf("再见啦!\n");
}
//主菜单
void showmain()
{
printf("*************************\n");
printf("小学生数学联系系统\n");
printf(" 1 加法 \n");
printf(" 2 减法 \n");
printf(" 3 乘法 \n");
printf(" 4 除法 \n");
printf(" 0 退出 \n");
printf("*************************\n");
printf("请选择(0-4):");
}
//选择模块
int getchoice()
{
int i;
scanf("%d", &i);
return i;
}
//加法
int add()
{
int x, y, result, score = 0;
printf("小朋友,开始做题了!!!\n");
srand((unsigned)time(NULL));
int i = 0;
while (i < num)
{
x = rand() % 100;
y = rand() % 100;
printf("%d+%d=", x, y);
scanf("%d", &result);
if (result == x + y)
{
printf("做对啦!!\n");
score += 10;
}
else
{
printf("做错了,继续加油!!!\n");
}
i++;
}
return score;
}
//减法
int sub()
{
int x, y, result, score = 0;
printf("小朋友,开始做题了!!!\n");
srand((unsigned)time(NULL));
int i = 0;
while (i < num)
{
x = rand() % 100;
y = rand() % 100;
printf("%d-%d=", x, y);
scanf("%d", &result);
if (result == x - y)
{
printf("做对啦!!\n");
score += 10;
}
else
{
printf("做错了,继续加油!!!\n");
}
i++;
}
return score;
}
//乘法
int mul()
{
int x, y, result, score = 0;
printf("小朋友,开始做题了!!!\n");
srand((unsigned)time(NULL));
int i = 0;
while (i < num)
{
x = rand() % 100;
y = rand() % 100;
printf("%d*%d=", x, y);
scanf("%d", &result);
if (result == x * y)
{
printf("做对啦!!\n");
score += 10;
}
else
{
printf("做错了,继续加油!!!\n");
}
i++;
}
return score;
}
//除法
int div()
{
int x, y, result, score = 0;
printf("小朋友,开始做题了!!!\n");
srand((unsigned)time(NULL));
int i = 0;
while (i < num)
{
x = rand() % 100;
y = rand() % 100;
if (y == 0)
{
continue;
}
printf("%d/%d=", x, y);
scanf("%d", &result);
if (result == x / y)
{
printf("做对啦!!\n");
score += 10;
}
else
{
printf("做错了,继续加油!!!\n");
}
i++;
}
return score;
}
//打印分数
void prnscore(int score)
{
printf("这次练习你一共得分;%d\n", score);
if (score >= 80)
printf("干得漂亮!!!\n");
else
printf("同志,继续加油!!!\n");
}
int main()
{
int choice = 0;
int score = 0;
while (1)
{
showmain();
score = 0;
choice = getchoice();
switch (choice)
{
case 1:score = add(); break;
case 2:score = sub(); break;
case 3:score = mul(); break;
case 4:score = div(); break;
}
if (choice == 0)
{
break;
}
prnscore(score);
}
exit();
}