Logo 
Search:

Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

Shell Scripting

  Asked By: Glenn    Date: Mar 06    Category: Unix / Linux / Ubuntu    Views: 2527
  

Im stuck on this, made some attempts but doesn't execute the way the task asks to. Any help is appreciated.


Write a script to prompt the user for two numbers, representing width and height of a rectangle in cm, and display the area of the rectangle both in square metres and in square inches ( 1 inch = 2.54 cm). Name this script "area.sh"

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Kirtiranjan Sahoo     Answered On: Aug 08

#!/bin/bash

read -p "Enter two numbers : " a b
w=`echo $a \* 0.01 | bc`
h=`echo $b \* 0.01 | bc`
area=`echo $w \* $h | bc`
echo "Area of rectangle in square meters : $area"
x=`echo $a \* 0.4 | bc`
y=`echo $b \* 0.4 | bc`
area=`echo $x \* $y | bc`
echo "Area of rectangle in square inches : $area"

 
Didn't find what you were looking for? Find more on Shell Scripting Or get search suggestion and latest updates.




Tagged: