The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Calculator
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-25-2008
ironhead3fan ironhead3fan is offline
Registered User
  
 

Join Date: Apr 2008
Location: Maryland
Posts: 3
Calculator

I am pretty new to the Unix word, and have created a working calculator script. I have one problem. It doesn't use any decimals, it rounds off to the nearest whole number.

1 #!/bin/ksh
2 while true; do
3 echo -n "Enter the first integer: "; read IN1
4 test "$OP1" = "x" && exit 0
5 echo -n "Enter an operator: "; read OPR
6 test "$OPR" = "x" && exit 0
7 echo -n "Enter the second integer: "; read IN2
8 test "$OP2" = "x" && exit 0
9 RES=$(expr "$IN1" "$OPR" "$IN2")
10 echo "Answer: $IN1 $OPR $IN2 = $RES";
11 done;

Any ideas? Thanks.