When I try to compile my code, I keep getting this error message:
badges.c: In function ‘badgeAnyColor’:
badges.c:335: error: label at end of compound statement
To help you see where it is complaining about, the complaints are on the last line of the switch statement, it says: "case 5: ". And one more concern I have is whether or not I'm doing the switch statement correctly syntax wise (I'm completely new to using switch statements with if/else statements) Help would be appreciated!
Here's my code:
int badgeAnyColor(int x, int y) {
int bronzebadges, northbadges, northeastbadges, northwestbadges, eastbadges,
westbadges, southbadges, southeastbadges, southwestbadges, polybadge;
double fs, ht, fp, sunexp, irrexp;
if ((x >= 1 && x <= 20) && (y >= 1 && y <= 20)) {
fs = fieldScore(x, y);
ht = harvestTime(x, y);
fp = fieldProfit(x, y);
sunexp = sunExposure(x, y);
irrexp = irrigationExposure(x, y);
bronzebadges = countBadges(x, y);
northbadges = countBadges(x, y + 1);
northeastbadges = countBadges(x + 1, y + 1);
northwestbadges = countBadges(x - 1, y + 1);
eastbadges = countBadges(x + 1, y);
westbadges = countBadges(x - 1, y);
southbadges = countBadges(x - 1, y - 1);
southeastbadges = countBadges(x + 1, y - 1);
southwestbadges = countBadges(x - 1, y - 1);
switch (bronzebadges) {
case 0: {
if (x == 1 && y == 1) {
if (northbadges == 0 && northeastbadges == 0 &&
eastbadges == 0) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 20 && y == 1) {
if (northbadges == 0 && northwestbadges == 0 &&
westbadges == 0) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 1 && y == 20) {
if (eastbadges == 0 && southeastbadges == 0 &&
southbadges == 0) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 20 && y == 20) {
if (westbadges == 0 && southwestbadges == 0 &&
southbadges == 0) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if ((x >= 2 && x <= 19) && y == 1) {
if (westbadges == 0 && northwestbadges == 0 && northbadges == 0
&& northeastbadges == 0 && eastbadges == 0) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
return polybadge;
}
case 1: {
if (fs >= 20) {
polybadge = 1;
}
else {
polybadge = 0;
}
return polybadge;
}
case 2: {
if (fp <= 0 || ht < 80 || sunexp > irrexp) {
polybadge = 1;
}
else {
polybadge = 0;
}
return polybadge;
}
case 3: {
if ((x >= 2 && x <= 19) && y == 1) {
if (((westbadges + northbadges) >= 2) || ((northbadges +
eastbadges) >= 2) || ((westbadges + eastbadges) >= 2)) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 1 && y == 1) {
if ((northbadges + eastbadges) >= 2) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 20 && y == 1) {
if ((northbadges + westbadges) >= 2) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 1 && y == 20) {
if ((southbadges + eastbadges) >= 2) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if (x == 20 && y == 20) {
if ((southbadges + westbadges) >= 2) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
if ((x >= 2 && x <= 19) && y == 20) {
if (((westbadges + southbadges) >= 2) || ((southbadges +
eastbadges) >= 2) || ((westbadges + eastbadges) >= 2)) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
else {
if (((northbadges + westbadges) >= 2) || ((westbadges +
southbadges) >= 2) || ((southbadges + eastbadges) >= 2) ||
((northbadges + southbadges) >= 2) || ((westbadges +
eastbadges) >= 2)) {
polybadge = 1;
}
else {
polybadge = 0;
}
}
return polybadge;
}
case 4:
case 5:
}
}
else {
polybadge = -1;
}
return polybadge;
}