-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (36 loc) · 757 Bytes
/
Copy pathmain.cpp
File metadata and controls
40 lines (36 loc) · 757 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
39
40
#include <iostream>
unsigned int getValue();
unsigned int getSumm(unsigned int number);
int main() {
std::cout << getSumm(getValue());
return 0;
}
unsigned int getValue()
{
while(true)
{
std::cout << "Enter number: ";
unsigned int value;
std::cin >> value;
if(std::cin.fail())
{
std::cin.clear();
std::cin.ignore(32767, '\n');
std::cout << "\nWrong size, please re-enter.\n";
}
else
{
return value;
}
}
}
unsigned int getSumm(unsigned int number)
{
unsigned long long sum = 0;
for(unsigned int i = 3; i <= number; ++i)
{
if(i % 3 == 0 || i % 5 == 0)
sum+=i;
}
return sum;
}