Question
4.5) Please use the solution to HW 7, problem 2, as a template to write a shell/awk script, myaverage4 , that reads in 4 numbers
4.5) Please use the solution to HW 7, problem 2, as a template to write a shell/awk script, myaverage4, that reads in 4 numbers and then uses a self-defined function to compute the average. The average should be displayed in the main program, not inside the function. Please use the following testing cases to test your script:
$ ./myaverage4 2 7 4 3
The average is 4
$./myaverage4 -2 -1 -4 -5
The average is -3
This is what i have:
#!/usr/bin/
echo $1 $2 $3 $4| awk '
{
print avg($1 $2 $3 $4)
}
function avg (a,b,c,d){
x=0
y=0
x = a + b + c + d
y = x / 4
return y
}'
it doesnt seem to be working.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started