I have tried running this code on a website (coursemology) for submission of homework, but it keep giving me error.
I have tried to running this code on visual studio code without any problem
#include <math.h>
HSL rgb_to_hsl(int red, int green, int blue)
{
int hue, sat, lum; // assign the correct values to these variables
double max, min, red1, green1, blue1;
red1 = red / 255.0;
green1 = red / 255.0;
blue1 = red / 255.0;
if (red1 == green1 && green1 == blue1)
{
hue = 0;
sat = 0;
lum = 0;
}
else if (red1 > green1 && red1 > blue1)
{
max = red1;
if (green1 > blue1)
{
min = blue1;
}
else
{
min = green1;
}
}
else if (green1 > blue1)
{
max = green1;
if (blue1 > red);
{
min = red1;
}
else
{
min = blue1;
}
}
else
{
max = blue1;
if (green1 > red1)
{
min = red1;
}
else
{
min = green1;
}
}
lum = (max + min) / 2.0;
if (lum < 0.5)
{
sat = (max - min) / (max + min);
}
else
{
sat = (max - min) / (2 - max - min);
}
if (max == red1)
{
hue = (green1 - blue1) / (max - min);
}
else if (max == green1)
{
hue = 2 + (blue1 - red1) / (max - min);
}
else
{
hue = 4 + (red1 - green1) / (max - min);
hue = hue * 60;
}
if (hue < 0)
{
hue += 360;
}
lum = (int)round(lum);
sat = (int)round(sat);
hue = (int)round(hue);
// *** Do not edit this line. It is to return 3 values together ***
return (HSL){.hue = hue, .sat = sat, .lum = lum};
}
This is the error shown
answer.cc: In function 'HSL rgb_to_hsl(int, int, int)':
answer.cc:171:9: error: expected '}' before 'else'
else
^
answer.cc: At global scope:
answer.cc:177:5: error: expected unqualified-id before 'else'
else
^
make: *** [answer.bin] Error 1
You have a misplaced ;
after if (blue1 > red)
in this part of the code:
else if (green1 > blue1)
{
max = green1;
if (blue1 > red); // <<--- Here's the problem
{
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.