The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-05-2008
Registered User
 

Join Date: May 2008
Posts: 1
Question Multiply variables

I have no idea about programming, just know some simple html and I need to get to somebody that can help me with creating the application (?) that will multiply 2 varibales and given price (height x lenght) x $$$.

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.
Reply With Quote
Forum Sponsor
  #2  
Old 05-06-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,260
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
Save this as "multiply.sh", do a "chmod 755 multiply.sh" and start it with "./multiply.sh".

I hope this helps.

bakunin
Reply With Quote
  #3  
Old 05-06-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0