forked from ChicoState/ColorHex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (38 loc) · 1.21 KB
/
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
42
43
44
45
#include <iostream>
const int RGB_HEX_LENGTH = 7;
const std::string NUMBERS = "0123456789";
const std::string LETTERS = "ABCDEFabcdef";
bool valid = false;
int arr[7] ={};
int main(){
std::string input;
do{
std::cout << "Enter a color in hex format (#RRGGBB):";
std::getline(std::cin, input);
if( input.size() != RGB_HEX_LENGTH || input[0] != "#"){
std::cout << "Please enter the color in hexadecimal format, starting with # followed by six hex values\n";
}
for(int i = 0; i < input.size(); i++){
for(int j = 0; j < NUMBERS.size(); j++){
if(input[i] == NUMBERS[j]){
arr[i] = 1;
}
}
for(int k = 0; k < LETTERS.size(); k++){
if(input [i] == LETTERS[k]){
arr[i] = 1;
}
}
}
for(int i = 0; i < RGB_HEX_LENGTH; i++){
if (arr[i] == 1){
valid = true;
}
else{
valid = false;
}
}
}while( input.size() != RGB_HEX_LENGTH || valid == false);
std::cout << "Your hex color is: " << input << std::endl;
return 0;
}