![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| multiply variable | fwabbly | Shell Programming and Scripting | 4 | 07-28-2007 02:26 PM |
| gawk multiply one field | pau | Shell Programming and Scripting | 2 | 05-28-2006 10:01 AM |
| How to add/multiply numbers with scientific notation (2.343e-5) | chugger06 | UNIX for Dummies Questions & Answers | 1 | 01-26-2006 07:03 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have no idea about programming, just know some simple html
PLEASE HELP! edit by bakunin: Anita, as much as we appreciate your question, i have to tell you that you posted it to the wrong forum part. This part, as the name should suggest, is a "Forum Support Area for Unregistered Users & Account Problems" an definitely not for a scripting problem such as yours. I will transfer your post to where it belongs, but i would like to ask you to place your postings right from now on. Last edited by bakunin; 05-06-2008 at 05:36 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You can do that with a little script like the one i have written for you. It will start over and wait for input as long as Input is non-zero. If it is it will terminate.
Note that the script makes no efforts to validate the input - entering a string or another nonsensical value instead of an (integer) number will cause a error message by the shell. Code:
#! /bin/ksh
typeset -i iLen=0
typeset -i iHgt=0
typeset -i iPrc=0
while : ; do
read iLen?"Enter length: "
if [ $iLen -le 0 ] ; then
exit 0
fi
read iHgt?"Enter height: "
if [ $iHgt -le 0 ] ; then
exit 0
fi
read iPrc?"Enter price : "
if [ $iPrc -le 0 ] ; then
exit 0
fi
print - "\nProduct (Length x Height x Price) is: $(( iLen * iHgt * iPrc ))"
print - "\n\n"
done
exit 0
I hope this helps. bakunin |
|
#3
|
|||
|
|||
|
And in ksh93 syntax:
Code:
#!/bin/ksh93
integer iLen=0
integer iHgt=0
integer iPrc=0
while : ; do
read iLen?"Enter length: "
(( $iLen <= 0 )) && exit 0
read iHgt?"Enter height: "
(( $iHgt <= 0 )) && exit 0
read iPrc?"Enter price : "
(( $iPrc <= 0 )) && exit 0
printf "\nProduct (Length x Height x Price) is: %d\n\n" $(( iLen * iHgt * iPrc ))
done
exit 0
|
|||
| Google The UNIX and Linux Forums |