Hey guys,
So I really need help writing a c++ program that is supposed to read in values for Red Green and Blue colors between 0 and 255, and then use a different function to convert them to Cyan Magenta Yellow and blacK color using set formulas.
1. Write a function that reads an RGB value and rejects invalid values.
2. Write a function max(a, b, c) that returns the maximum of its three parameters.
3. Write a function RGBtoCMYK(r, g, b, c, m, y, k) that receives RGB values as input parameters, and returns CMYK values as reference parameters.
So far my code reads in the numbers from the array but I cant figure out how to use the given formulas to change the data from RGB colors to CMYK colors.
Any kind of help is appreciated.
Thanks a lot.
Comment if you have any questions.
/*
Name: Colors
Author:
Date:
Description:
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
ifstream infile ("h.txt");
void readRGB(int r,int g,int b)
{
int red[9];
for (r=0; r <9; r++)
while (!infile.eof() && infile >> red[r]
)
cout << red[r] << endl;
}
int max (int a, int b, int c)
{
int max = a;
if (b > max)
max = b;
else if (c > max)
max = c;
return max;
}
void RGBtoCMYK (int r, int g, int b, int c, int m , int y, int k)
{
int w;
if (r == 0 && g == 0 && b == 0) {
c = 0;
m = 0;
y = 0;
k = 1;
cout << c << m << y << k << endl;
}
else {
w = max (r/255,g/255,b/255);
c = (w-(r/255))/ w;
m = (w-(g/255)) /w;
y = (w-(b/255)) / w;
k = 1 - w;
cout << c << m << y << k << endl;
}
}
int main ()
{
int r,b,g;
float c, m, y, k;
if ( !infile.is_open() ) {
cout << "ERROR: Unable to open file" << endl;
exit(1);
}
readRGB(r,g,b);
RGBtoCMYK(r, g, b, c,m, y, k);
}