forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
average.cpp.html
42 lines (38 loc) · 3.64 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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>average.cpp</title>
</head>
<body style="background-color:white">
<pre><b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<i><span style="color:#9A1900">/**</span></i>
<i><span style="color:#9A1900"> * </span></i><span style="color:#009900">@brief</span><i><span style="color:#9A1900"> Computes the average of the two passed values.</span></i>
<i><span style="color:#9A1900"> *</span></i>
<i><span style="color:#9A1900"> * This function computes the average using the standard accepted</span></i>
<i><span style="color:#9A1900"> * formula for doing so.</span></i>
<i><span style="color:#9A1900"> *</span></i>
<i><span style="color:#9A1900"> * </span></i><span style="color:#009900">@return</span><i><span style="color:#9A1900"> The average of the two passed values.</span></i>
<i><span style="color:#9A1900"> * </span></i><span style="color:#009900">@param</span><i><span style="color:#9A1900"> x The first value to average.</span></i>
<i><span style="color:#9A1900"> * </span></i><span style="color:#009900">@param</span><i><span style="color:#9A1900"> y The second value to average.</span></i>
<i><span style="color:#9A1900"> * </span></i><span style="color:#009900">@todo</span><i><span style="color:#9A1900"> Need to write acceptance tests for this function</span></i>
<i><span style="color:#9A1900"> */</span></i>
<span style="color:#009900">double</span> <b><span style="color:#000000">average</span></b> <span style="color:#990000">(</span><span style="color:#009900">double</span> x<span style="color:#990000">,</span> <span style="color:#009900">double</span> y<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#990000">(</span>x <span style="color:#990000">+</span> y<span style="color:#990000">)</span> <span style="color:#990000">/</span> <span style="color:#993399">2.0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">double</span> a<span style="color:#990000">,</span> b<span style="color:#990000">,</span> c<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Enter two different floating point numbers: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> a <span style="color:#990000">>></span> b<span style="color:#990000">;</span>
c <span style="color:#990000">=</span> <b><span style="color:#000000">average</span></b><span style="color:#990000">(</span>a<span style="color:#990000">,</span> b<span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The average of those numbers is "</span> <span style="color:#990000"><<</span> c <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>