diff --git a/README.md b/README.md index db2e196..295b950 100755 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ A collection of simple Bash scripts. 1. [Multiplication.sh](scripts/multiplication.sh): perform multiplication of two numbers 1. [Division.sh](scripts/division.sh): perform division of two numbers 1. [Simplecacl.sh](scripts/simplecalc.sh): a simple calculator +1. [Calculator.sh](scripts/calculator.sh): a simple calculator with user input capability 1. [Table.sh](scripts/table.sh): print table of any number 1. [EvenOdd.sh](scripts/evenodd.sh): check if a number input from standard input is odd or even 1. [Factorial.sh](scripts/factorial.sh): generate the factorial of a number @@ -58,6 +59,7 @@ A collection of simple Bash scripts. 1. [Binary2Decimal.sh](scripts/binary2decimal.sh): convert Binary Number back to decimal 1. [Decimal2Hex.sh](scripts/dec2hex.sh): convert Decimal Number to Hex 1. [Hex2Decimal](scripts/hextodec.sh): convert Hex number back to Decimal +1. [Area-Calculator.sh](scripts/area-calculator.sh): area calculator of any shape ## Image manipulation diff --git a/scripts/area-calculator.sh b/scripts/area-calculator.sh new file mode 100644 index 0000000..418aaa4 --- /dev/null +++ b/scripts/area-calculator.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# This script calculates the area of various shapes. + +echo "What shape do you want to calculate the area of? Choose from the following:" +echo "1. Square" +echo "2. Rectangle" +echo "3. Circle" +echo "4. Rhombus" +echo "5. Triangle" + +read choice + +case $choice in + 1) + echo "Enter the length of one side of the square:" + read length + area=$(echo "$length * $length" | bc) + echo "The area of the square is $area" + ;; + 2) + echo "Enter the length of the rectangle:" + read length + echo "Enter the width of the rectangle:" + read width + area=$(echo "$length * $width" | bc) + echo "The area of the rectangle is $area" + ;; + 3) + echo "Enter the radius of the circle:" + read radius + pi=$(echo "scale=10; 4*a(1)" | bc -l) + area=$(echo "$pi * $radius * $radius" | bc) + echo "The area of the circle is $area" + ;; + 4) + echo "Enter the length of one diagonal of the rhombus:" + read diagonal1 + echo "Enter the length of the other diagonal of the rhombus:" + read diagonal2 + area=$(echo "scale=2; ($diagonal1 * $diagonal2) / 2" | bc) + echo "The area of the rhombus is $area" + ;; + 5) + echo "Enter the base of the triangle:" + read base + echo "Enter the height of the triangle:" + read height + area=$(echo "scale=2; ($base * $height) / 2" | bc) + echo "The area of the triangle is $area" + ;; + *) + echo "Invalid choice" + ;; +esac diff --git a/calculator.sh b/scripts/calculator.sh similarity index 100% rename from calculator.sh rename to scripts/calculator.sh