#RGB TO HEXA & HEXA TO RGB C++
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Don't ask to ask a question, don't ask if anyone is familiar with XYZ. Just ask your question.
Someone is bound to know the answer and will be happy to help.
"Design a COLOR object with whatever methods and attributes you think are relevant.
Allow your data to be loaded in RGB or HEX, and return both as well" thats the statement
so what exactly do you expect as a response to that?
that we just do your homework for you? 😛
nope, i have that code i maded
/*
Diseñe un objeto COLOR con los métodos y atributos que considere pertinente.
Permita que se puedan cargar sus datos en RGB o HEXADECIMAL, y que devuelva ambos también
*/
#include <iostream>
#include <sstream>
using namespace std;
/*
Transformar RGB a HEXADECIMAL
*/
string rgbahexa(int r, int g, int b, bool a = false);
string rgbahexa(int r, int g, int b, bool a)
{
stringstream ss;
if (a)
ss << "#";
ss << hex << (r << 16 | g << 8 | b);
return ss.str();
}
int main(int argc, char *argv[]) {
int r,g,b;
cout << "Ingrese el valor RGB en este orden (Ejemplo: 22 10 22): ";
cin >> r >> g >> b;
cout << rgbahexa(r,b,g,true) << endl;
return 0;
}
im spanish btw
thats code works for rgb to hexa, but in a wrong way
• type three "backticks" (not quotes/apostrophes, on QWERTY layout, left of 1-key)
• on the same line, type the file extension for that language (c or cpp)
• enter your code on a new line and put another three backticks at the end
```cpp
int main() {
return 0;
}
```
int main() {
return 0;
} ```
what is wrong exactly?
this result need to be showed #160A16 but this is showed "#16160a" i used a rgb to hexa converter and this is wrong
and I don't know very well how to go from hexa to rgb (it's also part of the task)
hmm?
what happens?
well what do you think happens?
your code is doing that
cin >> r >> g >> b;
what do you think this does?
i have to go afk for a while i'm afraid
read the values entered by console? I think
oh, actually i solved it
i just changed
cin >> b >> g >> r;
cout << rgbahexa(b,g,r,true) << endl;
and worked
thanks a lot
I think it's fine, right?
now i need to convert from hexadecimal to rgb but i don't know well how to do it😢
/*
Diseñe un objeto COLOR con los métodos y atributos que considere pertinente.
Permita que se puedan cargar sus datos en RGB o HEXADECIMAL, y que devuelva ambos también
*/
#include <iostream>
#include <sstream>
using namespace std;
/*
Transformar RGB a HEXADECIMAL
*/
string rgbahexa(int r, int g, int b, bool a = false);
string rgbahexa(int r, int g, int b, bool a)
{
stringstream ss;
if (a)
ss << "#";
ss << hex << (r << 16 | g << 8 | b);
return ss.str();
}
int main(int argc, char *argv[]) {
int r,g,b;
cout << "Ingrese el valor RGB en este orden (Ejemplo: 22 10 22): ";
cin >> b >> g >> r;
cout << rgbahexa(b,g,r,true) << endl;
return 0;
}
that is my code to go from RGB to HEXA
@hollow gale Has your question been resolved? If so, run !solved :)
I don't see how cin >> b >> g >> r would work here
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.