Exercise 3

1 Creating a Function and Making a Function Call

Write a function, average, that returns the average of two Real values.


x
 
1
2

Make a function call to average with the input 4 and 6.


2
 
1
2

Try your function by calling it as below.


2
 
1
average(4, 6)
2

2
 
1
average(13.5, 19)
2

1.1

8
 
1
function average
2
  input Real a;
3
  input Real b;
4
  output Real result;
5
algorithm
6
  result := (a + b) / 2;
7
end average;
8

6
 
1
class AverageTest
2
  Real res;
3
equation
4
  res = average(4, 6);
5
end AverageTest;
6

1.1.1 Calling average

2
 
1
average(4, 6)
2

2
 
1
average(13.5, 19)
2