Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!bin/bash
- run=1
- while (run=1); do
- echo "hi"
- echo "Do you want to add(a), subtract(b), multiply(c), divide(d), or exit(e)?"
- read input
- if [[ $input == "a" ]]; then
- add
- elif [[ $input == "b" ]]; then
- subtract
- elif [[ $input == "c" ]]; then
- multiply
- elif [[ $input == "d" ]]; then
- divide
- elif [[ $input == "e" ]]; then
- exit
- else
- echo "Unexpected input, try again"
- fi
- done
- add () {
- echo "Please enter two numbers whole numbers your adding and the sum"
- read -r one
- read -r two
- read -r three
- result=$(($one +$two))
- if [[ $three -eq $result ]]; then
- echo "correct"
- else
- echo "false"
- fi
- run=0
- return $run
- }
- subtract () {
- echo "Please enter two numbers numbers your subtracting and the result"
- read -r one
- read -r two
- read -r three
- result=$(($one - $two))
- if [[ $three -eq $result ]]; then
- echo "Correct! The answer is $three"
- else
- echo "Wrong! The answer was $result"
- fi
- run=0
- return $run
- }
- divide () {
- echo "Please enter two numbers numbers your divided and the answer"
- read -r one
- read -r two
- read -r three
- result=$(($one / $two))
- if [[ $three = 0 ]]; then
- echo "Error! You can't divide by zero"
- elif [[ $three -eq $result ]]; then
- echo "Correct! The answer is $result"
- else
- echo "Wrong! The answer was $result"
- fi
- run=0
- return $run
- }
- multiply () {
- echo "Please enter two numbers numbers your multiplying and the answer"
- read -r one
- read -r two
- read -r three
- result=$(($one * $two))
- if [[ $result -eq $three ]]; then
- echo "Correct! The answer is $three"
- else
- echo "Wrong! The answer was $result"
- fi
- run=0
- return $run
- }
- exit () {
- echo "Goodbye"
- run=0
- return $run
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement