forked from ChicoState/ColorHex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
29 lines (20 loc) · 939 Bytes
/
main.cpp
File metadata and controls
29 lines (20 loc) · 939 Bytes
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
#include <iostream>
const int RGB_HEX_LENGTH = 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 ){
std::cout << "Please enter the color in hexadecimal format, starting with # followed by six hex values\n";
}
if(input[0] != '#')
std::cout << "Please put # first when entering the color in hexadecimal format\n";
for(int i = 0; i < input.size(); i++){
if((input[i] >= '0' && input[i] <= '9') || (input[i] >= 'a' && input[i] <= 'f') || (input[i] >= 'A' && input[i] <= 'F'))
std::cout << "Please enter the color in valid hexadecimal format, which involves 0-9, a-f, A-F\n";
}
}while( input.size() != RGB_HEX_LENGTH );
std::cout << "Your hex color is: " << input << std::endl;
return 0;
}