Hi,

In Visual Studio CLI. I have randomly generated numbers which are a,b,c,d . One by one they are meaningless . Together they create a color code for different products. For example :

id | a | b | c | d |
i | 1 | 1 | 5 | 9 |
i+1 | 6 | 0 | 2 | 1 |
i+2 | 9 | 0 | 0 | 3 |
.. ...
. ..

Aim is to save each 'a'b'c'd' row as a single number into array .

Am i in trouble ?? Please help, urgent ..
Any idea about the solution will be much appreciated.

Recommended Answers

All 4 Replies

What is the possible range of values for each of a,b,c,d? Zero to nine?

If so, then this might do what you want. If you can guarantee that the type of array is int, it can be simplified.

array[i] = 1000 * a + 100 * b + 10 * c + d;

d = array[i] % 10;
c = ((array[i] - d) %100)/10;
b = ((array[i] - d - c) % 1000)/100;
a = ((array[i] - d - c - b) /1000;

Colors are usually represented by three color gradients (either Red-Green-Blue for 'additive color' or Cyan-Yellow-Magenta for 'subtractive color'). This is because the human eye can differentiate three different clusters of wavelengths, with some overlap, so colors 'between' the main detected colors, such as orange, are actually detected by the green and red receptors, and so appear as a combination of the two.

Why am I mentioning all of this? Because you are using four sets of colors to represent the spectrum, which is unusual. What does the fourth number represent: 'pure' black (as with the 'Key' of the CMYK model? Pure white? Grayscale or 'tone'? An Alpha channel (transparency)? Or do you know at all? All this may be relevant to how you store the numbers, as is Moschops question about the range of the values (because that will tell you how many bits you'll need to represent each color).

What is the possible range of values for each of a,b,c,d? Zero to nine?

If so, then this might do what you want. If you can guarantee that the type of array is int, it can be simplified.

array[i] = 1000 * a + 100 * b + 10 * c + d;

d = array[i] % 10;
c = ((array[i] - d) %100)/10;
b = ((array[i] - d - c) % 1000)/100;
a = ((array[i] - d - c - b) /1000;

Thank you very much for your bright solution.

this is our revision,but we could not debug it. we just a beginner in c++. would you like to show to us the right way?

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    void determinant(int i, int j);
    int a1,a2,b1,b2,det;
    int det[2][2]={(11),(22),(33),(44)};
    for (int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            cout<<det[i][j]<<endl;


        cout<<"Enter the value a1:"<<endl;
        cin>>a1;
        cout<<endl<<endl;
    }


    cout<<"Enter the value a2:"<<endl;
    cin>>a2;
    cout<<endl<<endl;
    cout<<"Enter the value b1:"<<endl;
    cin>>b1;
    cout<<endl<<endl;

    cout<<"Enter the value b2:"<<endl;
    cin>>b2;
    cout<<endl<<endl;


}


    det =(a1*b2-a2*b1);

        cout << "The determinant is"<<det<<endl;

        system("pause");
        return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.