-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (37 loc) · 1.16 KB
/
Copy pathmain.cpp
File metadata and controls
48 lines (37 loc) · 1.16 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
#include <iostream>
#include <limits>
#include <array>
#include <string_view>
int main() {
constexpr std::string_view title = "Number-Array\n";
std::cout << title;
std::cout << "\tMax elements to number is 6\n";
std::cout << "\tArray type Integer\n";
std::cout << "\tArray numbers 0 - 1 - 2 - 3 - 4 - 5\n\n";
constexpr int32_t max_elements{6};
std::array<int32_t, max_elements> numbers{};
int32_t i{};
std::cout << "Create your own array\n";
while (i < max_elements) {
std::cout << "\tNumber[" << i + 1 << "]: ";
std::cin >> numbers[i];
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "\t[Error] Invalid input! Please enter an integer.\n";
continue;
}
i++;
}
std::cout << "\nYour array info:\n";
std::cout << "\tElements entered: ";
for (int32_t index{0}; const int32_t& num : numbers) {
std::cout << num;
if (index < max_elements - 1) {
std::cout << " - ";
}
index++;
}
std::cout << std::endl;
return 0;
}