stellarsystems
asked on
Help with calculator
Hi Guys please help,
You've picked Compare
Pick a number
1
Pick another number
5
First Number is less then the Second Number
The answere is: <-- need to remove this
Press Enter to continue...
You've picked Compare
Pick a number
1
Pick another number
5
First Number is less then the Second Number
The answere is: <-- need to remove this
Press Enter to continue...
echo " \"Welcome\" to the most awsome calc evar"
echo "1) Addition" #add two Numbers
echo "2) Subtract" #subtract two numbers
echo "3) Multiply" #multiply two numbers
echo "4) Divide" #divide two numbers
echo "5) Factorial" #Factorial two numbers
echo "6) Campare" #Campare two numbers
echo "7) EXIT" #exit the calculator
read CAL #get number for selection on CALC
while [ $CAL != 7 ]
#if CAL = to 7 will exit, if not continue next line
do
case $CAL in #database arrays
"1")
echo "You've picked Additions"
echo "Choose a number"
read NUM1
echo "Choose a another number to add to the first number"
read NUM2
VALUE=$(($NUM2+$NUM1))
;;
"2") echo "You've picked Subtract"
echo "Choose a number"
read NUM1
echo "Choose a another number to Subtract to the first number"
read NUM2
VALUE=$(($NUM1-$NUM2))
;;
"3") echo "You've picked Multiply"
echo "Choose a number"
read NUM1
echo "Choose a another to multiply"
read NUM2
VALUE=$(($NUM1*$NUM2))
;;
"4") echo "You've picked Divide"
echo "Choose a number"
read NUM1
echo "Choose a another to divide the first number"
read NUM2
VALUE=$(($NUM1/$NUM2))
;;
"5") echo "You've picked Factorial"
read NUM # get a number
FOR=1
FOR=$(($FOR*$NUM)) # FOR TIME NUM
NUM=$(($NUM-1)) # TAKE 1 OFF NUM
FOR=$(($FOR*$NUM)) #FOR TIMES WITH NUM
NUM=$(($NUM-1)) #TAKE 1 OFF NUM
while [ $NUM -gt 1 ] # LOOP UNTIL NUM = 1
do
FOR=$(($FOR*$NUM))
#times End by nu
NUM=$(($NUM-1))
#takes 1 off NUM
done
;;
"6") echo "You've picked Compare"
echo "Pick a number" #ask number
read NUM1 #ask another number
echo "Pick another number"
read NUM2
if [ $NUM1 -eq $NUM2 ] #if NUM1 = NUM2
then
echo "First Number is equal to Second Number" #show anwser NUM1=NUM2
else #or
if [ $NUM1 -lt $NUM2 ] #NUM1 less less than NUM2
then
echo "First Number is less then the Second Number" #show answer A less B
else
echo "First Number is Greater than Second Number" #or answer is A is Greater than B
fi
fi
;;
*)
echo "YOU ENTERED INVAILD OPTIONS"
echo "PLEASE TRY AGAIN"
;;
esac #show answer
echo "The answere is: $VALUE"
read -p "Press Enter to continue..." #pause for answere
clear
#space
echo " \"Welcome\" to the most awsome calc evar"
echo "1) Addition" #add two Numbers
echo "2) Subtract" #subtract two numbers
echo "3) Multiply" #multiply two numbers
echo "4) Divide" #divide two numbers
echo "5) Factorial" #Factorial two numbers
echo "6) Campare" #Campare two numbers
echo "7) EXIT" #exit the calculator
read CAL #get number for selection on CALC
done
ASKER
it all displays correctly except compare show the answer is after the if statements i need to stop this
Either delete line 82 or put a # sign in the first column to ignore the line altogether.
ASKER
no that wont word as i need that line for the rest of the calculator
Then you need to rewrite where the line is output. I get it, the example you have shown us does not add or subtract, it compares and gives the answer. You do not need the line "The Answer Is:" in this case but in other cases you do.
You could do this in a number of ways... Put the answer statement within the case section that needs it. This will require many duplicate line. Better way would be to place the lines in a subroutine that is called from with the case statements. I am certain I could come up with more...
You could do this in a number of ways... Put the answer statement within the case section that needs it. This will require many duplicate line. Better way would be to place the lines in a subroutine that is called from with the case statements. I am certain I could come up with more...
ASKER
Thanks technoweeb could you give an example on how id put the answere statement within the case section for each area? iv been trying but keep getting syntax errros
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So I am just curious... The last comment by the OP is that it was working.
I have been a member here for a very long time and it seems that answering or completing homework assignments has always been frowned upon by EE Staff and Community. This question, as well as at least one previous question from the OP appear as homework assignments. I chose to not challenge that fact for this question but give a push in the right direction so the OP can learn what it is they obviously want to learn. I do not find that learning is accomplished by someone just doing the work for me. I also do not know for 100% certainty that this was a homework assignment. I could have just as easily re-written the assignment and sent the OP on his way, but this is not truly in the spirit of the EE site.
I Think its working =)The comment after that was from Tintin who did what I suggested and rewrote the script using a function (I said subroutine, basically accomplishing the same outcome). He also contributed to the script with some clean ups as well.
spent a while but it now does what i want it too do thanks for the hints
I have been a member here for a very long time and it seems that answering or completing homework assignments has always been frowned upon by EE Staff and Community. This question, as well as at least one previous question from the OP appear as homework assignments. I chose to not challenge that fact for this question but give a push in the right direction so the OP can learn what it is they obviously want to learn. I do not find that learning is accomplished by someone just doing the work for me. I also do not know for 100% certainty that this was a homework assignment. I could have just as easily re-written the assignment and sent the OP on his way, but this is not truly in the spirit of the EE site.
I was not aware that this was a homework assignment. I assumed it was a self learning exercise.
If it is an assignment, then I definitely shouldn't have posted a full solution.
If it is an assignment, then I definitely shouldn't have posted a full solution.
ASKER
i figured it out with help from the community
On Line 82 you can change what you want to display on the screen:
Open in new window