Lab Task 3
Lab Task 3
Question1
Write a script that presents a menu with options like "Add", "Subtract", "Multiply",
and "Divide". Based on the user's choice, perform the corresponding operation. Take the
operands from the user as well.
Code
~$ #!/bin/bash
~$
~$ display_menu() {
>}
~$
~$ # Main loop
~$ while true; do
> display_menu
>
> break
> fi
>
> 1)
> ;;
> 2)
> ;;
> 3)
> ;;
> 4)
> else
> fi
> ;;
> *)
> ;;
> esac
> done
Output
Question1
Write a script that presents a menu with options like "Add", "Subtract", "Multiply",
and "Divide". Based on the user's choice, perform the corresponding operation. Take the
operands from the user as well.
Code
~$ #!/bin/bash
~$
~$ display_instructions() {
> echo "Please enter your marks for the following 5th semester courses:"
>}
~$
~$ calculate_gpa() {
> total_marks=0
> num_courses=5
>
> done
> done
>
>}
~$
~$ # Main loop
~$ while true; do
> display_instructions
> calculate_gpa
>
> read -p "Would you like to calculate GPA again? (yes/no): " choice
> break
> fi
> done
Output