[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[数值计算] 我用批处理做了一个计算器!可以运算小数,可以连续运算

我用批处理做了一个计算器,不像一般的批处理计算,这个可以运算小数,并且可以连乘连除连加连减,望大师们提提建议。使用方法:打开后输入你想要的运算类型,然后根据提示输入数字即可
如果想要运算小数,在选择运算类型时输入ps二字,回车后会再次出现提示要求选择运算类型,这里操作步骤同上
如果想要连加/减/乘/除,选择运算类型时输入many四字,回车后会再次提示要求选择运算类型,选择后回车,程序会提示你输入要连续加/减/乘/除几个数,目前支持3-5的数值,输入后回车,然后按照提示一步步输入你要计算的数字即可
  1. @echo off
  2. :cmd
  3. title 计算器
  4. :start
  5. set /p user_input=请选择一种运算:
  6. if %user_input% equ 乘法=goto a
  7. if %user_input% equ 除法=goto b
  8. if %user_input% equ 加法=goto c
  9. if %user_input% equ 减法=goto d
  10. if %user_input% equ ps=goto ps
  11. if %user_input% equ many=goto many
  12. goto start
  13. :a
  14. echo 请输入第一个因数
  15. set /p "A=>"
  16. echo 请输入第二个因数
  17. set /p "B=>"
  18. set /a result=%A%*%B%
  19. echo %result%
  20. pause
  21. goto start
  22. :b
  23. echo 请输入被除数
  24. set /p "A1=>"
  25. echo 请输入除数
  26. set /p "B1=>"
  27. set /a result=%A1%/%B1%
  28. echo %result%
  29. pause
  30. goto start
  31. :c
  32. echo 请输入第一个加数
  33. set /p "A2=>"
  34. echo 请输入第二个加数
  35. set /p "B2=>"
  36. set /a result=%A2%+%B2%
  37. echo %result%
  38. pause
  39. goto start
  40. :d
  41. echo 请输入被减数
  42. set /p "A3=>"
  43. echo 请输入减数
  44. set /p "B3=>"
  45. set /a result=%A3%-%B3%
  46. echo %result%
  47. pause
  48. goto start
  49. :ps
  50. title 计算器-PowerShell
  51. :psstart
  52. set /p user_input=请选择一种运算:
  53. if %user_input% equ 乘法=goto psa
  54. if %user_input% equ 除法=goto psb
  55. if %user_input% equ 加法=goto psc
  56. if %user_input% equ 减法=goto psd
  57. if %user_input% equ cmd=goto cmd
  58. if %user_input% equ many=goto many
  59. :psa
  60. echo 请输入第一个因数
  61. set /p "psA=>"
  62. echo 请输入第二个因数
  63. set /p "psB=>"
  64. powershell -command " ( %psA% * %psB% ) "
  65. pause
  66. goto psstart
  67. :psb
  68. echo 请输入被除数
  69. set /p "psA1=>"
  70. echo 请输入除数
  71. set /p "psB1=>"
  72. powershell -command " ( %psA1% / %psB1% ) "
  73. pause
  74. goto psstart
  75. :psc
  76. echo 请输入第一个加数
  77. set /p "psA2=>"
  78. echo 请输入第二个加数
  79. set /p "psB2=>"
  80. powershell -command " ( %psA2% + %psB2% ) "
  81. pause
  82. goto psstart
  83. :psd
  84. echo 请输入被减数
  85. set /p "psA3=>"
  86. echo 请输入减数
  87. set /p "psB3=>"
  88. powershell -command " ( %psA3% - %psB3% ) "
  89. pause
  90. goto psstart
  91. :many
  92. title 更多数字运算
  93. :mstart
  94. set /p user_input=请选择一种运算:
  95. if %user_input% equ 乘法=goto ma
  96. if %user_input% equ 除法=goto mb
  97. if %user_input% equ 加法=goto mc
  98. if %user_input% equ 减法=goto md
  99. if %user_input% equ ps=goto ps
  100. if %user_input% equ cmd=goto cmd
  101. goto mstart
  102. :ma
  103. set /p user_input=请输入需要运算的数字数量:
  104. if %user_input% equ 3=goto 1
  105. if %user_input% equ 4=goto 2
  106. if %user_input% equ 5=goto 3
  107. goto ma
  108. :1
  109. echo 请输入第一个因数
  110. set /p "mA=>"
  111. echo 请输入第二个因数
  112. set /p "mB=>"
  113. echo 请输入第三个因数
  114. set /p "mC=>"
  115. powershell -command " ( %mA% * %mB% * %mC%) "
  116. pause
  117. goto mstart
  118. :2
  119. echo 请输入第一个因数
  120. set /p "mA1=>"
  121. echo 请输入第二个因数
  122. set /p "mB1=>"
  123. echo 请输入第三个因数
  124. set /p "mC1=>"
  125. echo 请输入第四个因数
  126. set /p "mD1=>"
  127. powershell -command " ( %mA1% * %mB1% * %mC1% * %mD1%) "
  128. pause
  129. goto mstart
  130. :3
  131. echo 请输入第一个因数
  132. set /p "mA2=>"
  133. echo 请输入第二个因数
  134. set /p "mB2=>"
  135. echo 请输入第三个因数
  136. set /p "mC2=>"
  137. echo 请输入第四个因数
  138. set /p "mD2=>"
  139. echo 请输入第五个因数
  140. set /p "mE2=>"
  141. powershell -command " ( %mA2% * %mB2% * %mC2% * %mD2% * %mE2%) "
  142. pause
  143. goto mstart
  144. :mb
  145. set /p user_input=请输入需要运算的数字数量:
  146. if %user_input% equ 3=goto 1a
  147. if %user_input% equ 4=goto 2a
  148. if %user_input% equ 5=goto 3a
  149. goto mb
  150. :1a
  151. echo 请输入被除数
  152. set /p "mmA=>"
  153. echo 请输入第一个除数
  154. set /p "mmB=>"
  155. echo 请输入第二个除数
  156. set /p "mmC=>"
  157. powershell -command " ( %mmA% / %mmB% / %mmC%) "
  158. pause
  159. goto mstart
  160. :2a
  161. echo 请输入被除数
  162. set /p "mmA1=>"
  163. echo 请输入第一个除数
  164. set /p "mmB1=>"
  165. echo 请输入第二个除数
  166. set /p "mmC1=>"
  167. echo 请输入第三个除数
  168. set /p "mmD1=>"
  169. powershell -command " ( %mmA1% / %mmB1% / %mmC1% / %mmD1%) "
  170. pause
  171. goto mstart
  172. :3a
  173. echo 请输入被除数
  174. set /p "mmA2=>"
  175. echo 请输入第一个除数
  176. set /p "mmB2=>"
  177. echo 请输入第二个除数
  178. set /p "mmC2=>"
  179. echo 请输入第三个除数
  180. set /p "mmD2=>"
  181. echo 请输入第四个除数
  182. set /p "mmE2=>"
  183. powershell -command " ( %mmA2% / %mmB2% / %mmC2% / %mmD2% / %mmE2%) "
  184. pause
  185. goto mstart
  186. :mc
  187. set /p user_input=请输入需要运算的数字数量:
  188. if %user_input% equ 3=goto 1b
  189. if %user_input% equ 4=goto 2b
  190. if %user_input% equ 5=goto 3b
  191. goto mc
  192. :1b
  193. echo 请输入第一个加数
  194. set /p "mmmA=>"
  195. echo 请输入第二个加数
  196. set /p "mmmB=>"
  197. echo 请输入第三个加数
  198. set /p "mmmC=>"
  199. powershell -command " ( %mmmA% + %mmmB% + %mmmC%) "
  200. pause
  201. goto mstart
  202. :2b
  203. echo 请输入第一个加数
  204. set /p "mmmA=>"
  205. echo 请输入第二个加数
  206. set /p "mmmB=>"
  207. echo 请输入第三个加数
  208. set /p "mmmC=>"
  209. echo 请输入第四个加数
  210. set /p "mmmD=>"
  211. powershell -command " ( %mmmA% + %mmmB% + %mmmC% + %mmmD%) "
  212. pause
  213. goto mstart
  214. :3b
  215. echo 请输入第一个加数
  216. set /p "mmmA=>"
  217. echo 请输入第二个加数
  218. set /p "mmmB=>"
  219. echo 请输入第三个加数
  220. set /p "mmmC=>"
  221. echo 请输入第四个加数
  222. set /p "mmmD=>"
  223. echo 请输入第五个加数
  224. set /p "mmmE=>"
  225. powershell -command " ( %mmmA% + %mmmB% + %mmmC% + %mmmD% + %mmmE%) "
  226. pause
  227. goto mstart
  228. :md
  229. set /p user_input=请输入需要运算的数字数量:
  230. if %user_input% equ 3=goto 1c
  231. if %user_input% equ 4=goto 2c
  232. if %user_input% equ 5=goto 3c
  233. goto md
  234. :1c
  235. echo 请输入被减数
  236. set /p "mmmmA=>"
  237. echo 请输入第一个减数
  238. set /p "mmmmB=>"
  239. echo 请输入第二个减数
  240. set /p "mmmmC=>"
  241. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC%) "
  242. pause
  243. goto mstart
  244. :2c
  245. echo 请输入被减数
  246. set /p "mmmmA=>"
  247. echo 请输入第一个减数
  248. set /p "mmmmB=>"
  249. echo 请输入第二个减数
  250. set /p "mmmmC=>"
  251. echo 请输入第三个减数
  252. set /p "mmmmD=>"
  253. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC% - %mmmmD%) "
  254. pause
  255. goto mstart
  256. :3c
  257. echo 请输入被减数
  258. set /p "mmmmA=>"
  259. echo 请输入第一个减数
  260. set /p "mmmmB=>"
  261. echo 请输入第二个减数
  262. set /p "mmmmC=>"
  263. echo 请输入第三个减数
  264. set /p "mmmmD=>"
  265. echo 请输入第四个减数
  266. set /p "mmmmE=>"
  267. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC% - %mmmmD% - %mmmmE%) "
  268. pause
  269. goto mstart
复制代码

关于小数运算调用了PowerShell来进行运算

TOP

回复 1# LTSC1809


    你好作者,代码很好,我想转用一下,可否?非常感谢!
QQ 1980286392

TOP

回复 3# BingjianREMIX 当然可以
一个六年级小学生,请多指教

TOP

我稍微改动了一点,将他英化了
  1. @echo off
  2. :cmd
  3. title Calculator
  4. :start
  5. cls
  6. echo ---------------------
  7. echo MICRODOS CALCULATOR
  8. echo ---------------------
  9. echo.
  10. echo 1.Multiplication
  11. echo.
  12. echo 2.Division
  13. echo.
  14. echo 3.Addition
  15. echo.
  16. echo 4.Subtraction
  17. echo.
  18. echo 5.Decimal Calculate
  19. echo.
  20. echo 6.Multiple Number Calculation
  21. echo.
  22. echo Q.Exit
  23. echo.
  24. set /p user_input=Please select an operation:
  25. if %user_input% equ 1=goto a
  26. if %user_input% equ 2=goto b
  27. if %user_input% equ 3=goto c
  28. if %user_input% equ 4=goto d
  29. if %user_input% equ 5=goto ps
  30. if %user_input% equ 6=goto many
  31. if /i "%user_input%"=="Q" exit /b
  32. cls
  33. echo ERROR!
  34. pause>nul
  35. goto start
  36. :a
  37. cls
  38. echo Please enter the first factor.
  39. set /p "A=>>>"
  40. echo Please enter the second factor.
  41. set /p "B=>>>"
  42. set /a result=%A%*%B%
  43. echo %result%
  44. pause
  45. goto start
  46. :b
  47. cls
  48. echo Please enter dividend.
  49. set /p "A1=>>>"
  50. echo Please enter a divisor.
  51. set /p "B1=>>>"
  52. set /a result=%A1%/%B1%
  53. echo %result%
  54. pause
  55. goto start
  56. :c
  57. cls
  58. echo Please enter the first addend.
  59. set /p "A2=>>>"
  60. echo Please enter the second addend.
  61. set /p "B2=>>>"
  62. set /a result=%A2%+%B2%
  63. echo %result%
  64. pause
  65. goto start
  66. :d
  67. cls
  68. echo Please enter the minuend.
  69. set /p "A3=>>>"
  70. echo Please enter a reduction.
  71. set /p "B3=>>>"
  72. set /a result=%A3%-%B3%
  73. echo %result%
  74. pause
  75. goto start
  76. :ps
  77. title Calculator-PowerShell
  78. :psstart
  79. cls
  80. echo ---------------------
  81. echo MICRODOS CALCULATOR
  82. echo ---------------------
  83. echo.
  84. echo 1.Multiplication
  85. echo.
  86. echo 2.Division
  87. echo.
  88. echo 3.Addition
  89. echo.
  90. echo 4.Subtraction
  91. echo.
  92. echo 5.Integer calculation
  93. echo.
  94. echo Q.Exit
  95. echo.
  96. set /p user_input=Please select an operation:
  97. if %user_input% equ 1=goto psa
  98. if %user_input% equ 2=goto psb
  99. if %user_input% equ 3=goto psc
  100. if %user_input% equ 4=goto psd
  101. if %user_input% equ 5=goto cmd
  102. if /i "%user_input%"=="Q" exit /b
  103. cls
  104. echo ERROR!
  105. pause>nul
  106. goto pssstart
  107. :psa
  108. cls
  109. echo Please enter the first factor.
  110. set /p "psA=>>>"
  111. echo Please enter the second factor
  112. set /p "psB=>>>"
  113. powershell -command " ( %psA% * %psB% ) "
  114. pause
  115. goto psstart
  116. :psb
  117. cls
  118. echo Please enter dividend.
  119. set /p "psA1=>>>"
  120. echo Please enter a divisor.
  121. set /p "psB1=>>>"
  122. powershell -command " ( %psA1% / %psB1% ) "
  123. pause
  124. goto psstart
  125. :psc
  126. cls
  127. echo Please enter the first addend.
  128. set /p "psA2=>>>"
  129. echo Please enter the second addend.
  130. set /p "psB2=>>>"
  131. powershell -command " ( %psA2% + %psB2% ) "
  132. pause
  133. goto psstart
  134. :psd
  135. cls
  136. echo Please enter the minuend.
  137. set /p "psA3=>>>"
  138. echo Please enter a reduction.
  139. set /p "psB3=>>>"
  140. powershell -command " ( %psA3% - %psB3% ) "
  141. pause
  142. goto psstart
  143. :many
  144. title Calculator-More Calculate Way
  145. :mstart
  146. cls
  147. echo ---------------------
  148. echo MICRODOS CALCULATOR
  149. echo ---------------------
  150. echo.
  151. echo 1.Multiplication
  152. echo.
  153. echo 2.Division
  154. echo.
  155. echo 3.Addition
  156. echo.
  157. echo 4.Subtraction
  158. echo.
  159. echo 5.Decimal Calculate
  160. echo.
  161. echo 6.Multiple Number Calculation
  162. echo.
  163. echo Q.Exit
  164. echo.
  165. set /p user_input=Please select an operation:
  166. if %user_input% equ 1=goto ma
  167. if %user_input% equ 2=goto mb
  168. if %user_input% equ 3=goto mc
  169. if %user_input% equ 4=goto md
  170. if %user_input% equ 5=goto ps
  171. if %user_input% equ 6=goto cmd
  172. if /i "%user_input%"=="Q" exit /b
  173. cls
  174. echo ERROR!
  175. pause>nul
  176. goto mstart
  177. :ma
  178. cls
  179. echo.
  180. echo Up to 5 numbers can be calculated simultaneously.
  181. echo.
  182. echo You can choose a number calculation between 3-5
  183. echo.
  184. set /p user_input=Please enter the number of numbers to be calculated:
  185. if %user_input% equ 3=goto 1
  186. if %user_input% equ 4=goto 2
  187. if %user_input% equ 5=goto 3
  188. goto ma
  189. :1
  190. cls
  191. echo Please enter the first factor.
  192. set /p "mA=>>>"
  193. echo Please enter the second factor.
  194. set /p "mB=>>>"
  195. echo Please enter the third factor.
  196. set /p "mC=>>>"
  197. powershell -command " ( %mA% * %mB% * %mC%) "
  198. pause
  199. goto mstart
  200. :2
  201. cls
  202. echo Please enter the first factor
  203. set /p "mA1=>>>"
  204. echo Please enter the second factor
  205. set /p "mB1=>>>"
  206. echo Please enter the third factor
  207. set /p "mC1=>>>"
  208. echo Please enter the fourth factor
  209. set /p "mD1=>>>"
  210. powershell -command " ( %mA1% * %mB1% * %mC1% * %mD1%) "
  211. pause
  212. goto mstart
  213. :3
  214. cls
  215. echo Please enter the first factor
  216. set /p "mA2=>>>"
  217. echo Please enter the second factor
  218. set /p "mB2=>>>"
  219. echo Please enter the third factor
  220. set /p "mC2=>>>"
  221. echo Please enter the fourth factor
  222. set /p "mD2=>>>"
  223. echo Please enter the fifth factor
  224. set /p "mE2=>>>"
  225. powershell -command " ( %mA2% * %mB2% * %mC2% * %mD2% * %mE2%) "
  226. pause
  227. goto mstart
  228. :mb
  229. cls
  230. echo.
  231. echo Up to 5 numbers can be calculated simultaneously.
  232. echo.
  233. echo You can choose a number calculation between 3-5
  234. echo.
  235. set /p user_input=Please enter the number of numbers to be calculated:
  236. if %user_input% equ 3=goto 1a
  237. if %user_input% equ 4=goto 2a
  238. if %user_input% equ 5=goto 3a
  239. goto mb
  240. :1a
  241. cls
  242. echo Please enter the divisor
  243. set /p "mmA=>>>"
  244. echo Enter the first divisor
  245. set /p "mmB=>>>"
  246. echo Enter the second divisor
  247. set /p "mmC=>>>"
  248. powershell -command " ( %mmA% / %mmB% / %mmC%) "
  249. pause
  250. goto mstart
  251. :2a
  252. cls
  253. echo Please enter the divisor
  254. set /p "mmA1=>>>"
  255. echo Enter the first divisor
  256. set /p "mmB1=>>>"
  257. echo Enter the second divisor
  258. set /p "mmC1=>>>"
  259. echo Enter the third divisor
  260. set /p "mmD1=>>>"
  261. powershell -command " ( %mmA1% / %mmB1% / %mmC1% / %mmD1%) "
  262. pause
  263. goto mstart
  264. :3a
  265. cls
  266. echo Please enter the divisor
  267. set /p "mmA2=>>>"
  268. echo Enter the first divisor
  269. set /p "mmB2=>>>"
  270. echo Enter the second divisor
  271. set /p "mmC2=>>>"
  272. echo Enter the third divisor
  273. set /p "mmD2=>>>"
  274. echo Enter the fourth divisor
  275. set /p "mmE2=>>>"
  276. powershell -command " ( %mmA2% / %mmB2% / %mmC2% / %mmD2% / %mmE2%) "
  277. pause
  278. goto mstart
  279. :mc
  280. cls
  281. echo.
  282. echo Up to 5 numbers can be calculated simultaneously.
  283. echo.
  284. echo You can choose a number calculation between 3-5
  285. echo.
  286. set /p user_input=Please enter the number of numbers to be calculated:
  287. if %user_input% equ 3=goto 1b
  288. if %user_input% equ 4=goto 2b
  289. if %user_input% equ 5=goto 3b
  290. goto mc
  291. :1b
  292. cls
  293. echo Please enter the first addition
  294. set /p "mmmA=>>>"
  295. echo Please enter the second addition
  296. set /p "mmmB=>>>"
  297. echo Please enter the third addition
  298. set /p "mmmC=>>>"
  299. powershell -command " ( %mmmA% + %mmmB% + %mmmC%) "
  300. pause
  301. goto mstart
  302. :2b
  303. cls
  304. echo Please enter the first addition
  305. set /p "mmmA=>>>"
  306. echo Please enter the second addition
  307. set /p "mmmB=>>>"
  308. echo Please enter the third addition
  309. set /p "mmmC=>>>"
  310. echo Please enter the fourth addition
  311. set /p "mmmD=>>>"
  312. powershell -command " ( %mmmA% + %mmmB% + %mmmC% + %mmmD%) "
  313. pause
  314. goto mstart
  315. :3b
  316. cls
  317. echo Please enter the first addition
  318. set /p "mmmA=>>>"
  319. echo Please enter the second addition
  320. set /p "mmmB=>>>"
  321. echo Please enter the third addition
  322. set /p "mmmC=>>>"
  323. echo Please enter the fourth addition
  324. set /p "mmmD=>>>"
  325. echo Please enter the fifth addition
  326. set /p "mmmE=>>>"
  327. powershell -command " ( %mmmA% + %mmmB% + %mmmC% + %mmmD% + %mmmE%) "
  328. pause
  329. goto mstart
  330. :md
  331. cls
  332. echo.
  333. echo Up to 5 numbers can be calculated simultaneously.
  334. echo.
  335. echo You can choose a number calculation between 3-5
  336. echo.
  337. set /p user_input=Please enter the number of numbers to be calculated:
  338. if %user_input% equ 3=goto 1c
  339. if %user_input% equ 4=goto 2c
  340. if %user_input% equ 5=goto 3c
  341. goto md
  342. :1c
  343. cls
  344. echo Please enter the minus
  345. set /p "mmmmA=>>>"
  346. echo Please enter the first minus
  347. set /p "mmmmB=>>>"
  348. echo Please enter the second minus
  349. set /p "mmmmC=>>>"
  350. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC%) "
  351. pause
  352. goto mstart
  353. :2c
  354. cls
  355. echo Please enter the minus
  356. set /p "mmmmA=>>>"
  357. echo Please enter the first minus
  358. set /p "mmmmB=>>>"
  359. echo Please enter the second minus
  360. set /p "mmmmC=>>>"
  361. echo Please enter the third minus
  362. set /p "mmmmD=>>>"
  363. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC% - %mmmmD%) "
  364. pause
  365. goto mstart
  366. :3c
  367. cls
  368. echo Please enter the minus
  369. set /p "mmmmA=>>>"
  370. echo Please enter the first minus
  371. set /p "mmmmB=>>>"
  372. echo Please enter the second minus
  373. set /p "mmmmC=>>>"
  374. echo Please enter the third minus
  375. set /p "mmmmD=>>>"
  376. echo Please enter the fourth minus
  377. set /p "mmmmE=>>>"
  378. powershell -command " ( %mmmmA% - %mmmmB% - %mmmmC% - %mmmmD% - %mmmmE%) "
  379. pause
  380. goto mstart
复制代码
QQ 1980286392

TOP

返回列表