免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1430 | 回复: 4
打印 上一主题 下一主题

求出 小弟初学 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-25 02:32 |只看该作者 |倒序浏览
Write a shell script to simulate a simple calculator. Sample output is as follows.
建一个脚本 简单的计算器 运行如下
tsaiy:/./calculator
enter the first number
6
enter the second number
8
enter operand
*
the result is 48
tsaiy:/./calculator
enter the first number
50
enter the second number
25
enter operand
/
the result is 2

论坛徽章:
0
2 [报告]
发表于 2011-02-25 09:08 |只看该作者
做作业?

论坛徽章:
0
3 [报告]
发表于 2011-02-25 09:26 |只看该作者
不是呀 练习题

论坛徽章:
0
4 [报告]
发表于 2011-02-25 09:42 |只看该作者
  1. #!/bin/bash
  2. echo "enter the first number"
  3. read a
  4. echo "enter the second number"
  5. read b
  6. echo "enter operand"
  7. read oper
  8. case "$oper" in
  9. "+" )
  10.     ((b=a+b))
  11.    echo "the result is $b"
  12.    ;;
  13. "-" )
  14.     ((b=a-b))
  15.     echo "the result is $b"
  16.     ;;
  17. "*" )
  18.     ((b=a*b))
  19.     echo "the result is $b"
  20.     ;;
  21. "/" )
  22.     if [ "$b" -eq "0" ]
  23.     then
  24.         echo "Error"
  25.     else
  26.         ((b=a/b))
  27.         echo "the result is $b"
  28.     fi
  29.     ;;
  30. *   )
  31.     echo "Error"
  32.     ;;
  33. esac
复制代码
回复 3# hzy12359

论坛徽章:
0
5 [报告]
发表于 2011-02-25 12:51 |只看该作者
回复 1# hzy12359


    好好做作业吧,出来了有用,别浪费了学习的机会
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP