[help c++] code coach - Hex color code generator | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

[help c++] code coach - Hex color code generator

I don't get how this works. Please help me to understand. ---------Task: Create a function that accepts three integers that represent the RGB (red, green, blue) values and outputs the hex-code representation. Input Format: Three integers that represent RGB values. Output Format: The hexadecimal color code string that corresponds with the entered RGB values. ***Sample Input: 100 200 233 Sample Output: #64c8e9 ***Explanation: Hex color codes work within 15 characters, 0-9 and a-f. RGB goes into hex color codes as such # (red) 00 (green) 00 (blue) 00. Hex color codes work by rolling over the value of 09 to 0a. Once Of is hit (15) the following value (16) would be represented as 10 instead of (16). This means the RGB values (16, 32, 161) would evaluate to # 1020a1 (10, 20, a1).

11th Mar 2023, 6:48 PM
Jasmine
Jasmine - avatar
5 Respuestas
+ 6
Jasmine , > please start a serious try by yourself first. > if you get stuck somewhere, post a link to your code here. > give a description what your issue is.
11th Mar 2023, 7:46 PM
Lothar
Lothar - avatar
+ 4
Jasmine for now forget about RGB and stuff, just read 3 numbers, then print a '#' character followed by those numbers you just read, without any spaces, converted to base 16. so if you read 32 127 204 then you just print #207fcc 32(base 10) = 20(base 16) 127 = 7f 204 = cc Some more info, skip if you like : #xxxxxx is just a format to represent a color in HTML, nothing more. first xx is for red, then green, then blue, like #rrggbb range of each color is between 0 to 255 (0x00 to 0xff in base 16) thus 2 hex digits are enough for each color. Even more: this code coach seems to have a bug, that is all input values are above 15 (or 0x0f). this makes it easier, e.g. if it had values of say 10 11 12 you had to print a '0' before each one: #0a0b0c then it was correct, #abc is still a valid HTML color but totally different from #0a0b0c, or it just doesn't care in the hidden test cases.
12th Mar 2023, 6:26 PM
Tina
Tina - avatar
+ 3
Jasmine you're welcome! glad I could help! well, hex is very useful for making big numbers and addresses shorter, maskings, etc... also easier for converting to binary (which is obviously a must).
12th Mar 2023, 7:58 PM
Tina
Tina - avatar
+ 2
Tina 🇺🇦🇮🇷🇹🇷 Great thank you so much for the explanation and extension. I solved this. I shouldn't have skipped the hexadecimal lesson. ^^
12th Mar 2023, 7:42 PM
Jasmine
Jasmine - avatar
+ 1
Lothar Umm, not the code. I don't understand the explanation. Can you help me understand?
12th Mar 2023, 5:05 PM
Jasmine
Jasmine - avatar