-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (33 loc) · 799 Bytes
/
main.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
#include <iostream>
#include <string>
bool isAlphanumerical(const std::string& string)
{
bool result{ true };
for(char character : string)
{
const bool isDigit = character >= '0' && character <= '9';
const bool isLetter = (character >= 'A' && character <= 'Z') ||
(character >= 'a' && character <= 'z');
if(!isDigit && !isLetter)
{
result = false;
break;
}
}
return result;
}
int main()
{
std::string input;
std::cout << "Please enter a string: ";
std::getline(std::cin, input);
std::cout << '\n';
if (isAlphanumerical(input))
std::cout << input << " is alphanumerical!" << '\n';
else
std::cout << input << " is not alphanumerical!" << '\n';
std::cout << '\n';
std::cout << "Press Enter to continue . . . ";
std::cin.get();
return 0;
}