I'm trying to write a program that will ask the user to input the number of values he wants, prompt him for the values and then print out the maximum value and the minimum value.
This is what I have so far:

count=1
echo "Enter number of integers"
read n


while [ $count -le $n ]
do
        echo "Enter integer"
        read x

        current=$x

        if [ $current -gt $x ];
        then
                max=$current
        fi

        if [ $current -lt $x ];
        then
                min=$current
        fi
done


echo "Max value is $max"
echo "Min value is $min"

You set current=$x and then look for $current to be something other than $x. What you probably want is to check if [ $current -gt $max ] and if [ $current -lt $min ]. Other than that your logic looks in order.

commented: wrong answer +0

use C++

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.