Modify the addi command to loop until the user enters quit and to allow users to specify what function they want to apply to the pair of numbers given so that the following session would work.

$ addi
100 200
300
100 - 50
50
5 * 5
25
5/5
error: not enough arguments given
quit
$

#
# add pairs of integers on standard input
#

echo "> \c"

while read n1 n2 n3
do
if [ "$n1" = "quit" ] ; then
exit 0
fi

if [ -n "$n3" ] ; then
# we have three arguments if n3 is non-null
echo $(( $n1 $n2 $n3 ))
else
echo $(( $n1 + $n2))
fi

echo "> \c"

done

Computer Science & Information Technology

You might also like to view...

A stack is the ideal collection to use when _______________________

a) implementing a radix sort b) evaluating a postfix expression c) modeling customers standing in line at the checkout of a grocery store d) finding the largest number in an array e) none of the above

Computer Science & Information Technology

Suppose the following sequence of elements are pushed onto a stack named myStack in the following order: 50, 26, 32, 18, 26, 51. What is the output of the following code?

What will be an ideal response? ``` for (int count = 1; count <=3; count++) System.out.println(myStack.pop() ); ```

Computer Science & Information Technology