-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddEm.cpp
More file actions
42 lines (32 loc) · 943 Bytes
/
addEm.cpp
File metadata and controls
42 lines (32 loc) · 943 Bytes
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
//============================================================
//addem.cpp
// a code to add numbers provided via cin and report the
// sum back via cout
// ==========================================================
#include <iostream>
using namespace std;
//Declaration of functions defined elsewhere
double sumNumbers(istream & dataSource);
//============>> main << =====================================
int main()
{
double sum = sumNumbers(cin);// get the sum
cout<< " The sum is " << sum << endl;
return 0;
}
//sumNumbers is a function that sums a list of numbers
//via a dataSource , until there are no more
//numbers forthcoming
//===========================================================
double sumNumbers(istream & dataSource)
{
double sum = 0.0;
double number;
dataSource >> number;
while( not dataSource.fail() )
{
sum=sum+number;
dataSource >> number; //try for another
}
return sum;
}