This like of code seems to give the correct result in Filter-more exercise in CS50.
int r = round(sqrt(pow(rgx, 2) + pow(rgy, 2)));
int g = round(sqrt(pow(ggx, 2) + pow(ggy, 2)));
int b = round(sqrt(pow(bgx, 2) + pow(bgy, 2)));
if (r > 255)
{
r = 255;
}
if (g > 255)
{
g = 255;
}
if (b > 255)
{
b = 255;
}
copy[i][j].rgbtRed = r;
copy[i][j].rgbtGreen = g;
copy[i][j].rgbtBlue = b;
But this code doesnt seem to work. Seems to Me that both codes are very similar.
copy[i][j].rgbtRed = round(sqrt(pow(rgx, 2) + pow(rgy, 2)));
copy[i][j].rgbtGreen = round(sqrt(pow(ggx, 2) + pow(ggy, 2)));
copy[i][j].rgbtBlue = round(sqrt(pow(bgx, 2) + pow(bgy, 2)));
if (copy[i][j].rgbtRed > 255)
{
copy[i][j].rgbtRed = 255;
}
if (copy[i][j].rgbtGreen > 255)
{
copy[i][j].rgbtGreen = 255;
}
if (copy[i][j].rgbtBlue > 255)
{
copy[i][j].rgbtBlue = 255;
}
New contributor
Bharath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3