Where to being Comparing numbers?

Hi. I do not know how to compare numbers and need help. In my script I have to figure the MAX, MIN, & Avg. Sales amounts.
Please help me.
In the code, "transaction" is a counter.

 
#!/bin/bash
        clear
        transaction=0
        sales=0
        total=0
        while test $sales
        do
                echo -e "Enter sales price: \c"
                read sales
                let transaction=$transaction+1
                let total=total+sales
        done
        echo "Number of Transactions :" $transaction
        echo "Total Sales:" $total
                if test $total -lt 100
                then
                echo " Sorry, we do not take credit cards for sales less than $100.  "
                fi

Thanks

I didn't have bash in my system but i hope this might do what u were trying to do...

#!/bin/sh
        clear
        total=0
        transaction=0
        ans="Y"
        while [[ $ans = "Y" ]]
        do
                echo  "Enter sales price: \c"
                read sales
                transaction=`expr $transaction + 1`
                total=`expr $total + $sales`
                echo "Do you want to add transaction(Y/N): \c"
                read ans
        done
        echo "Number of Transactions :" $transaction
        echo "Total Sales:" $total
                if [[ $total -lt 100 ]]
                then
                echo " Sorry, we do not take credit cards for sales less than 100.  "
                fi

the `expr` statement is a bit obsolete, and following statements can normally be written

# transaction=`expr $transaction + 1`
((transaction++))
# total=`expr $total + $sales`
((total+=sales))

there is no need of bouble brackets there
# if [[ $total -lt 100 ]]
if [ $total -lt 100 ]

Thank you Malcomex999 (smile) and Frans.
But I don't see how to find the Max or Min in your examples. Did I miss something? :confused:
Many, many thanks.
Ccccc

Something like this:

#/bin/bash
clear
transaction=0
sales=0
total=0
MIN=0
MAX=0
while true
do
    echo -e "Enter sales price: \c"
    read sales
    $((sales)) || break # if sales = 0 then finish
    [ $sales -gt $MAX ] && MAX=$sales
    [ $transaction -eq 0 ] || [ $sales -lt $MIN ] && MIN=$sales
    $((transaction++))
    $((total+=sales))
done
echo "Number of Transactions : $transaction"
echo "Total Sales : $total"
echo "Max amount : $MAX"
echo "Min amount : $MIN"
echo "Average : $((total/transaction))"
[ $total -lt 100 ] && echo " Sorry, we do not take credit cards for sales less than $100."

Hi.
I've tried to figure out this error message but no luck. This code was sent in by Frans.
When I enter the Sales Price I get this msg:
"./ss: line 11: 2: command not found"
Transactions :
Total Sales :
max : 0
min : 0
./ss: line 21: total/transaction: division by 0 (error token is "transaction")
./ss: line 22: [: -lt unary oprator expected

I don't understand why it is complaining about "command not found".

clear
  trans=0
   sales=0
   MIN=0
   MAX=0
   while true
   do
   echo -e "Enter sales price: \c"
  read sales
line 11   $((sales)) || break # if sales = 0 then finish
  [ $sales -gt $MAX ] && MAX=$sales
  [ $transaction -eq 0 ] || [ $sales -lt $MIN ] && MIN=$sales
  $((transaction++))
  $((total+=sales))
  done
  echo "Transactions : $transaction"
  echo "Total Sales : $total"
  echo "max : $MAX"
  echo "min : $MIN"
  echo "Avg : $((total/transaction))"
  [ $total -lt 100 ] && echo "sorry no credit"

Thanks for your help.
Ccccc

try to replace

$((sales)) || break

by

[ "$sales" -ne 0 ] || break

Thanks Frans.
That worked just great, but my old nemesis is here: unary operator expected.
Line 14: [: -eq: unary operator expected ]
Thanks so much for your help. :slight_smile:
Ccccc

Remove these $ signs:

  $((transaction++))
  $((total+=sales))

Thanks Frans. Thanks Franklin52.
This was really a baptism in "unary operator expected" and "integer expression expected". Finally the light came on AND it was not a train at the end of the tunnel. (hahahahahahaha...):b::slight_smile: