FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp_tests/t26_simple_program.cpp at master · s-kramer/cpp_tests · GitHub
s-kramer
/
cpp_tests
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp_tests
/
t26_simple_program.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (27 loc) · 763 Bytes
Breadcrumbs
cpp_tests
/
t26_simple_program.cpp
Copy path
File metadata and controls
30 lines (27 loc) · 763 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
const
int
LOWER_VAL
=
5
;
const
int
UPPER_VAL
=
9
;
bool
is_in_range
(
int
val,
int
lower =
LOWER_VAL
,
int
upper =
UPPER_VAL
)
{
return
(val >= lower && val <=upper);
}
int
main
()
{
long
int
sum =
0
;
double
average =
0
;
unsigned
count =
0
;
int
num =
0
;
while
(
1
) {
std::cout <<
"
Enter number from the range 5 - 9 inclusive:
\n
"
;
std::cin >> num;
if
(!
is_in_range
(num)) {
std::cout <<
"
The number
"
<< num <<
"
is not within the range <
"
<<
LOWER_VAL
<<
"
,
"
<<
UPPER_VAL
<<
"
>.
\n
"
;
continue
;
}
sum += num;
count++;
average =
static_cast
<
double
>(sum) / count;
std::cout <<
"
Current average:
"
<< average <<
'
\n
'
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL