#!/bin/bash
for ((i=1 ;i<=3;i++))
do
echo "Enter gallon used(gal):"
read gal
echo "Enter Miles Obtained(mil):"
read mil
mileage=`echo $mil / $gal |bc`
echo "scale=4; $mileage " | bc
c=`echo $c + $mileage | bc`
echo "$c + $mileage = $c"
echo
done
|
||||
closed as unclear what you're asking by cuonglm, X Tian, Anthon, maxschlepzig, Jenny D Jun 29 at 16:27Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. |
||||
See these, too: |
|||||||||||||||||||||
|
Is you get an integer result because there is no operation in line 9, Merge lines 8 and 9 to then milage will have a decimal result.
You do not do anything useful with |
|||||||||
|
c=`echo $c + $mileage | bc`
;echo $c + $mileage | bc
is (obviously) run before the shell assigns its output to$c
, so$c
is undeclared while runningecho $c + $mileage | bc
– kos Jun 29 at 14:02