-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe10.cpp
58 lines (51 loc) · 1.09 KB
/
e10.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "../std_lib_facilities.h"
int main ()
{
int N {0};
string input;
double sum {0};
vector<double> numbers;
vector<double> differences;
cout << "Please enter the number of values you want to sum: " << endl;
cin >> input;
if (stoi(input))
{
N = stoi(input);
}
cout << "Please enter some integers (press '|' to stop): " << endl;
for (double temp ; cin >> temp ;)
{
numbers.push_back(temp);
}
if (numbers.empty())
{
error("No numbers found.");
}
else if (N > numbers.size())
{
error("Numbers to sum is larger then available numbers.");
}
if (numbers.size() == 1)
{
cout << "There are one number ( " << numbers.front() << " )." << endl;
}
else
{
cout << "The sum of the first " << N << " numbers ( ";
for (int i = 0 ; i < N ; i++)
{
sum += numbers[i];
cout << numbers[i] << " ";
if (numbers[i] != numbers[N - 1])
{
differences.push_back(numbers[i] - numbers[i + 1]);
}
}
cout << ") is " << sum << "." << endl;
cout << "The differences between adjacent values are:" << endl;
for (auto d : differences)
{
cout << d << " ";
}
}
}