Sponsored Content
Full Discussion: Help with assignment2
Homework and Emergencies Homework & Coursework Questions Help with assignment2 Post 302477493 by newbee006 on Sunday 5th of December 2010 10:43:21 PM
Old 12-05-2010
Hi,
Sorry for not explaining properly.
But I am done the verification part.
Here is my verifcation part,
Code:
x=$1
y=$2
z=$3

#This if statement checks if there ar any arguments is or not.

if [ "$#" = 0 ]; then
echo "Please enter data in one line seperated by a space. ex; CAD 2000 INR" ; read x y z
set $x $y $z
fi

#This if statement checks if there are 2 or 3 arguments or not.

if [ "$#" -lt 2 ] ; then
echo "          You entered "$*
echo $# "arguments were entered, please enter 2 or 3 arguments" ; read x y z


#This if statement checks if argument 1 is CAD or USA or not.

elif [ "$#" -eq 2 ]; then
echo ""
elif ! echo $1| grep -Ewq '[A-Z][A-Z][A-Z]|[A-z][a-z][a-z]' ; then
echo "          You entered "$1 $2
echo $1 "is an invalid entry, please re-enter new data."i ; read x y z

#This if statement checks if argument 2 is numeric or not.

elif  echo $2| grep -vq "^-\?[0-9]\+$" &&  echo $2| grep -vq "^-\?[0-9]*[0-9]\.[0-9]$" && echo $2| grep -vq "^-\?[0-9]*[0-9]\.[0-9][0-9]$"; then
echo "          You entered "$1 $2
echo $2 "is an invalid entry, please re-enter new data." ; read x y z

else

#This if statement checks if there are 3 arguments entered and they all are correct.

        if ! echo $1| grep -Ewq '[A-Z][A-Z][A-Z]|[A-z][a-z][a-z]'; then
                echo "          You entered "$1 $2 $3
                echo $1 "is an invalid entry, please re-enter new data." ; read x y z

        elif  echo  $2| grep -vq "^-\?[0-9]\+$" &&  echo  $2| grep -vq "^-\?[0-9]*[0-9]\.[0-9]$" && echo  $2| grep -vq "^-\?[0-9]*[0-9]\.[0-9][0-9]$"; then
                echo "          You entered "$1 $2 $3
                echo $2 "is an invalid entry, please re-enter new data." ; read x y z

        elif ! echo $3| grep -Ewq '[A-Z][A-Z][A-Z]|[A-z][a-z][a-z]'; then
                echo "          You entered "$1 $2 $3
                echo $3 "is an invalid entry, please re-enter new data." ; read x y z

        elif [ "$#" -gt 3 ] ; then
        echo "          You entered "$*
        echo $# "arguments were entered, please enter 2 or 3 arguments" ; read x y z

        fi
fi


All want to do is, get this output.
Output part:
  • Each time your output is referring to Canadian or US Dollars, the dollar number must be preceded by a $ sign, such as $1540 Canadian, or $164.55 US. (The word Dollar should not appear).
  • The resultant currency displayed and the currency exchange rate should always be rounded off to 2 decimal places.
  • The output of the script should be formatted so that the name of the country in the 1st 2 lines, always starts at the 1st character on the screen, the decimal point of the currency exchange rates should always be the 35th character, and the currency unit always starts at character 41.
Example 2:
-> as per this example i have to get the decimal point on 35th char, and "D" of Dollar on 41st char.
$ exchange.bash CAD 50 Irr
Canadian: 1.00 Dollar
Iranian: 10230.19 Rial

-> For this line, I need to get "s" after Dollar or Rial if its more than 1.
$50 Canadian is equivalent to 511509.50 Iranian Rials.
  • If the original or resulting amount is more than 1 then you must display the currency name with an "s" at the end, e.g. Rials versus Rial.
  • The resulting output line must be in the format and text as per examples provided.
-> to get this kind of example i have done this,
->the echo line is checking if the decimal point is on 35th char and the "D" of Dollar on 41st char on both line generated by 1st two awk line.
but its not correct it doesnt work properly.
Code:
echo "12345678901234567890123456789012345678901234567890"
awk '$3~/'$x'/ {printf "%s: %35s %41s ",$1, $4, $2}' convert.table.103
awk '$3~/'$z'/ {printf "\n%s: %27.2f %41c \n",$1, $4, $2}' convert.table.103

->this awk fetches data from the file and does the math,
Code:
 
awk -v original="$x" -v new="$z" '$3~/'$z'/ {value='$2'*$4;printf  "\n$%.2f %s is equal to  %.2f %s\n", '$y',$1,value, $1 ,$2}'  convert.table


hope you get what i want to say.


---------- Post updated at 10:43 PM ---------- Previous update was at 01:08 PM ----------

THis thread is closed now.
THank you for ur help.

Last edited by newbee006; 12-05-2010 at 02:26 PM..
 
All times are GMT -4. The time now is 01:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy