当前位置:DOS资源站资料中心批处理教程 → 批处理小学生四则运算练习

批处理小学生四则运算练习

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-4-23 21:32:05

@echo off &title DOS资源站 www.cmdos.net
set /a duitimes=0
set /a cuotimes=0
set /a times=0
:top
title …………………………………………小学生四则运算练习…………………………………………
color 1a
echo.
echo.
echo         你想进行哪个范围内的练习?
echo.
echo         注意事项:1、练习进行时按 Q 键显示得分并退出
echo                   2、对于除法,只输入整数部分即可
echo            1、10以内
echo            2、100以内
echo            3、1000以内
echo            4、10000以内
echo            5、32767以内
set /p fanwei=     请你选择:
if %fanwei% equ 1 set /a fanwei=10&goto start
if %fanwei% equ 2 set /a fanwei=100&goto start
if %fanwei% equ 3 set /a fanwei=1000&goto start
if %fanwei% equ 4 set /a fanwei=10000&goto start
if %fanwei% equ 5 set /a fanwei=32767&goto start
cls&goto top
:start
:a1
set a1=%random%
set /a a1=%a1%%%fanwei%
:a2
set a2=%random%
set /a a2=%a2%%%fanwei%
if %a2% equ 0 goto a2  rem 这一行保证第二个数不是0,免得计算除法时出错。
set a3=%random%
set /a si=4
set /a fuhao=%a3%%%si%
if %fuhao% equ 0 set jjcc=+
if %fuhao% equ 1 set jjcc=- & set /a xsss=%a1%-%a2%
if %fuhao% equ 2 set jjcc=×
if %fuhao% equ 3 set jjcc=÷
:feifu
set /a times=%times%+1
set /p xsss=    第 %times% 道:  %a1%%jjcc%%a2%=
if %xsss% equ Q goto end
if %xsss% equ q goto end
if %jjcc% equ + set /a zqjg=%a1%+%a2%
if %jjcc% equ - set /a zqjg=%a1%-%a2%
if %jjcc% equ × set /a zqjg=%a1%*%a2%
if %jjcc% equ ÷ set /a zqjg=%a1%/%a2%
if %xsss% equ %zqjg% set /a duitimes=%duitimes%+1&echo                              正确!&echo %a1%%jjcc%%a2%=%xsss%…………√ >>四则运算.txt
if %xsss% neq %zqjg% set /a cuotimes=%cuotimes%+1&echo                              错误!&echo %a1%%jjcc%%a2%=%xsss%…………× >>四则运算.txt
goto start
:end
set /a times=%duitimes%+%cuotimes%
set /a duilv=%duitimes%*100
set /a duirate=%duilv%/%times%
echo.
echo          你共做了 %times% 道题。
echo          对了 %duitimes% 道,
echo          错了 %cuotimes% 道。
echo          正确率约为 %duirate%%%%。
echo.
if %duirate% lss 31 echo        评语:你太差劲了!应该努力了!!&goto over
if %duirate% lss 61 echo        评语:你的水平一般!如果努力,会有提高!&goto over
if %duirate% lss 81 echo        评语:不错!继续努力啊!&goto over
if %duirate% lss 101 echo        评语:很好很好,你真是太厉害了!佩服!&goto over
:over
echo.&echo         你做的题目保存在 四则运算.txt 中,你可以自己打开复习。&echo.
pause


这个文件有两个毛病:
1,第二个数为了照顾除法,已经限制不能是0,对加法,减法,乘法有点不公平
2,对于除法,只能输入整数部分,有小数点就出错,因为批处理不支持小数.
算完后会生成txt文件,里面纪录着算术的对错