Bash scripting/linux

A programe that asks a user to enter the age of the people in his family and calculates the average and product of their age



#!/bin/bash
read -p "enter your name " name
    while [ -z "$name" ] 
    do
read -p "you must enter your name " name
      done
       
read -p "enter your reg no " regno
while [ -z "$regno" ] 
    do
read -p "you must enter your regno " regno
      done
read -p "enter mother's_age " mother_age
while [ -z "$mother_age" ] 
    do
read -p "you must enter your mothers_age " mother_age
      done
read -p "enter father's_age " father_age
while [ -z "$father_age" ] 
    do
read -p "you must enter your fathers_age " father_age
      done
read -p "enter my_age " my_age
while [ -z "$my_age" ] 
    do
read -p "you must enter your age " my_age
      done

while [ $my_age -ge $mother_age ] || [ $my_age -ge $father_age  ]
    do
    read -p "enter your correct _age becouse you cant be older than your mother" my_age
    done
read -p "enter  sister_age's_age " sister_age

while [ $sister_age -ge $mother_age ] || [ $sister_age -ge $father_age  ]
    do
    read -p "enter your correct _age " sister_age
    done

read -p "enter your young bro's_age " yo_bro_age

while [ $yo_bro_age -ge  $my_age ]
    do   
    read -p "enter your correct young bro's_age " yo_bro_age
    done
   
read -p "enter number of people in afamily " number
while [ -z "$number" ] 
    do
read -p "you must enter the number of people in the family " number
      done
read -p "enter number of years you have spent in school " years
while [ $years -ge  $my_age ]
    do   
    read -p "enter your correct years you have spent in school " years
    done
   
        if [ $my_age = $yo_bro_age ]
            then
            echo "you and yo bro you are twins CONGuLATULATIONS!!!!!!!!!"
        elif [ $my_age = $sister_age ]
            then
            echo "you and yo sister you are twins CONGuLATULATIONS!!!!!!!!!"
        fi
       
        #calculating there average
total=$((mother_age + father_age + my_age + sister_age + brother_age))
echo "your name is : $name"
echo "your regno is : $regno"

#outputting there average
echo "average age = $((total / number)) "

#outputting the product of the average and number of years spent in school
echo "product  = $((total / number * years))"

No comments:

Post a Comment