forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage.cpp.html
42 lines (36 loc) · 3.15 KB
/
average.cpp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>average.cpp</title>
</head>
<body bgcolor="white">
<pre><tt><b><font color="#000080">#include</font></b> <font color="#FF0000"><iostream></font>
<b><font color="#0000FF">using</font></b> <b><font color="#0000FF">namespace</font></b> std<font color="#990000">;</font>
<i><font color="#9A1900">/** </font></i><font color="#009900">@brief</font><i><font color="#9A1900"> Computes the average of the two passed values.</font></i>
<i><font color="#9A1900"> *</font></i>
<i><font color="#9A1900"> * This function computes the average using the standard accepted</font></i>
<i><font color="#9A1900"> * formula for doing so.</font></i>
<i><font color="#9A1900"> * </font></i><font color="#009900">@return</font><i><font color="#9A1900"> The average of the two passed values.</font></i>
<i><font color="#9A1900"> * </font></i><font color="#009900">@param</font><i><font color="#9A1900"> x The first value to average.</font></i>
<i><font color="#9A1900"> * </font></i><font color="#009900">@param</font><i><font color="#9A1900"> y The second value to average.</font></i>
<i><font color="#9A1900"> * </font></i><font color="#009900">@todo</font><i><font color="#9A1900"> Need to write acceptance tests for this function</font></i>
<i><font color="#9A1900"> */</font></i>
<font color="#009900">double</font> <b><font color="#000000">average</font></b> <font color="#990000">(</font><font color="#009900">double</font> x<font color="#990000">,</font> <font color="#009900">double</font> y<font color="#990000">)</font> <font color="#FF0000">{</font>
<b><font color="#0000FF">return</font></b> <font color="#990000">(</font>x<font color="#990000">+</font>y<font color="#990000">)/</font><font color="#993399">2.0</font><font color="#990000">;</font>
<font color="#FF0000">}</font>
<font color="#009900">int</font> <b><font color="#000000">main</font></b> <font color="#990000">()</font> <font color="#FF0000">{</font>
<font color="#009900">double</font> a<font color="#990000">,</font> b<font color="#990000">,</font> c<font color="#990000">;</font>
cout <font color="#990000"><<</font> <font color="#FF0000">"Enter two different floating point numbers: "</font> <font color="#990000"><<</font> endl<font color="#990000">;</font>
cin <font color="#990000">>></font> a <font color="#990000">>></font> b<font color="#990000">;</font>
c <font color="#990000">=</font> <b><font color="#000000">average</font></b><font color="#990000">(</font>a<font color="#990000">,</font>b<font color="#990000">);</font>
cout <font color="#990000"><<</font> <font color="#FF0000">"The average of those numbers is "</font> <font color="#990000"><<</font> c <font color="#990000"><<</font> endl<font color="#990000">;</font>
<b><font color="#0000FF">return</font></b> <font color="#993399">0</font><font color="#990000">;</font>
<font color="#FF0000">}</font>
</tt></pre>
</body>
</html>