forked from ChicoState/ColorHex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
38 lines (32 loc) · 946 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
#include <iostream>
#include <ctype.h>
using namespace std;
const int RGB_HEX_LENGTH = 7;
int main(){
std::string input;
bool test1 = false;
bool test2 = false;
do{
std::cout << "Enter a color in hex format (#RRGGBB):";
std::getline(std::cin, input);
if (input.at(0) == '#')
test1 = true;
for (int i = 1; i < input.size(); i++)
{
if (isdigit(input.at(i)))
{
test2 = true;
}
else
{
test2 = false;
break;
}
}
if( input.size() != RGB_HEX_LENGTH || !test1 || !test2){
std::cout << "Please enter the color in hexadecimal format, starting with # followed by six hex values\n";
}
}while( input.size() != RGB_HEX_LENGTH || !test1 || !test2);
std::cout << "Your hex color is: " << input << std::endl;
return 0;
}