-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram1_2.cpp
More file actions
65 lines (54 loc) · 1.14 KB
/
Copy pathProgram1_2.cpp
File metadata and controls
65 lines (54 loc) · 1.14 KB
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
59
60
61
62
63
64
65
#include <iostream>
#include <limits>
#include <string_view>
#include "Program1_2.h"
namespace programs
{
namespace
{
template <typename Integer>
void printRange()
{
std::cout << '[' << std::numeric_limits<Integer>::lowest() << ", "
<< std::numeric_limits<Integer>::max() << ']';
}
template <typename Integer>
bool readAndWriteInteger(std::string_view article, std::string_view typeName)
{
std::cout << "Enter " << article << ' ' << typeName << " value in the range ";
printRange<Integer>();
std::cout << ": " << std::flush;
Integer value{};
if (!(std::cin >> value))
{
return false;
}
std::cout << "The " << typeName << " value is " << value << '\n';
return true;
}
}
void runProgram1_2()
{
if (!readAndWriteInteger<short>("a", "short int"))
{
return;
}
if (!readAndWriteInteger<unsigned short>("an", "unsigned short int"))
{
return;
}
if (!readAndWriteInteger<int>("an", "int"))
{
return;
}
if (!readAndWriteInteger<unsigned int>("an", "unsigned int"))
{
return;
}
if (!readAndWriteInteger<long>("a", "long int"))
{
return;
}
readAndWriteInteger<unsigned long>("an", "unsigned long int");
}
}