In the code, the $total2 of each product is placed in an array so that when the question is answered "no", we have "n" arrays. What loop can I do to add them all in a single variable and print it to the screen?
#!/bin/bash clear read -p "Do you want to continue shopping?: " response while [ "$response" == 'yes' ] do read -p "What product are you going to buy?" product read -p "What is the price of this product?: " price read -p "How much of this product will you take?: " quantity lettotal2=expr $precio\*$cantidad
echo "$product ($price €) X $quantity = $total2 €" array[i]=$total2 ((i++)) read -p "Do you want to continue shopping?: " response if [ "$answer" == 'no' ] then break fi donatehere I want to add all the arrays created to show that sum on the screen.
echo "The total purchase price is $sum €."
#
Go accumulating the total value in a variable:
So, all your code can be something like: