Pls help with script made a calculator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pls help with script made a calculator
# 1  
Old 08-20-2015
Pls help with script made a calculator

Hello, I'm in need with a little help for my script please this is the brief i need to complete which I haven't been able to do:

On option 7 stop the calculator

The calculator will keep running until option 7 is chosen. Any other option than 1-7 will generate an error message.

Pls any help greatly appreciated thanks

this is my code:
Code:
#!/bin/sh

	echo "1. Area of Circle"
	echo "2. Area of Rectangle"
	echo "3. Area of Square"
	echo "4. Area of Triangle"
	echo "5. Factorial"
	echo "6. Compare"
        echo "7. Exit"
	echo "enter the choice of operation -->"
	read c
	case $c in
1) 
	echo -n "Enter radius of circle -->"
	read r
	echo -n "Area of circle is --> $carea"
	carea= echo "3.14*$r*$r"|bc
;;
2)
	echo -n "Enter Length of Rectangle -->"
	read l
	echo -n "Enter Breadth of Rectangle -->"
	read b
	rarea=`expr $l \* $b`
	echo "Area of Rectangle is --> $rarea"
;;
3)
	echo -n "Enter Length of Square -->"
	read l
	sarea=`expr $l \* $l`
	echo "Area of Square is --> $sarea"
;;
4)
	echo -n "Please enter the base and height of the triangle --> "
	read base 
	read height
	area=`expr "scale=2; 1/2*$base*$height" |bc`
	echo "area of the triangle = $area"
;;
5)
	echo "Total no of factorial wants"
	read fact
	
	ans=1
	counter=0
	while [ $fact -ne $counter ]
do
        counter=`expr $counter + 1`
        ans=`expr $ans \* $counter`
done
	echo "Total of factorial is $ans"
;;
6)
	echo "Compare Numbers"
	echo ""
	echo "Enter a first value"
	read FIRST
	echo ""
	echo "Enter a second number"
	read SECOND
	echo ""
	if [ $FIRST = $SECOND ]
	then
		OUTPUT="Both values are equal"
	else
		if [ $FIRST -gt $SECOND ]
		then
			OUTPUT="$FIRST is greater"
		else
			OUTPUT="$SECOND if greater"
	fi
		fi
		echo $OUTPUT
		echo ""

;;
*)
echo "wrong input"
;;
esac

# 2  
Old 08-21-2015
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script Calculator

Hello, I have to make a calculator in shell script. But I get this error. Can someone help me please? c.sh: 3: c.sh: i: not found That's my code. ========================================================================== #Calculator i = "yes" while do echo What operation... (2 Replies)
Discussion started by: KJN
2 Replies

2. Shell Programming and Scripting

CSH Calculator Script

Using the C Shell, I'm building a script that will compute simple mathematical computations (addition, subtraction, multiplication, division). The user will enter two integers (operands) on the command line separated by the operation (operator) they wish to perform. Example of the command line... (7 Replies)
Discussion started by: ksmarine1980
7 Replies

3. Shell Programming and Scripting

chmod calculator script

so just spit ballin here, i was wondering if anybody knew how to make a chmod calculator script. basically go to this website http://mistupid.com/internet/chmod.htm i would like something like this that i can use in a terminal tho. so like i run the scrip and it ask for owner what... (1 Reply)
Discussion started by: hookitup
1 Replies

4. Shell Programming and Scripting

Script to send alert if any changes are made in crontab.

Hi i want to know how can i write a script to check if any changes are made and send an alert in crontabs . i am using .ksh file extension for writing scripts. (3 Replies)
Discussion started by: honey26
3 Replies

5. Shell Programming and Scripting

Prompt home made script

Hi I made a script called mydf which puts out the amount of storage space left on the file system; df | head -2 | tail -1 | tr -s " " | cut -d" " -f4 But I would like to run it with every new prompt, so you get something like; user@5518748~$ in your prompt (5518748 being the mydf output). Its... (2 Replies)
Discussion started by: mdop
2 Replies

6. Homework & Coursework Questions

Problem with calculator script

I'm having some trouble implementing a basic calculator using command line options. The script is supposed to take (multiple) arguments -a,-d,-m,-s for addition, multiplication, division, and subtraction. I'm pretty sure I know how to parse through the options with getopt(), but I have no idea... (17 Replies)
Discussion started by: zkapopou
17 Replies

7. Shell Programming and Scripting

Improve script made to calculate value based on present and previous line

Hi all, I have made at small script to make a simple calculation on a file which is formatted in this way: I want to create a new file in which the value of particular line minus the previous line is printed. So my wanted output is: I have made the following program to do the job... (5 Replies)
Discussion started by: s052866
5 Replies

8. Shell Programming and Scripting

How do I assign values to variables made in a script?

How do I assign values to variables made in a script? e.g. for ((x=0;x<=5;i+=1)); do Xm$i=$var done (0 Replies)
Discussion started by: gelitini
0 Replies

9. Shell Programming and Scripting

Pls. Help my script not working as it should

I'm using nested for loops to gather ping IP addresses from a hostlist and also changing the packet size via a packet size list. The final results of (RTT and SDEV) will need to be grep'd out using awk into variables and then printed in columns (the packet sizes going across with IP address going... (1 Reply)
Discussion started by: cocoabeauty1
1 Replies

10. UNIX for Dummies Questions & Answers

Made command into a script but now won't run

Hello, After seeing in a Unix cheatsheet that I could add commands into a file and run that file as a command to save on typing, i tried it with this: #! /bin/csh # Backup website excluding directories that do not change rsync -e "ssh -p 2222" -axzvc --progress --stats --compress-level=9... (9 Replies)
Discussion started by: patwa
9 Replies
Login or Register to Ask a Question