电脑网络

C++这个出错了expectedunqualified-idbefore'return'

346 浏览

C++这个出错了expected unqualified-id before 'return'

1 个回答

AndreaNUG用户头像
AndreaNUG 回答于 2024-07-20
已采纳

提问:C++这个出错了expectedunqualified-idbefore'return'

//各种控制反应 switch (map[snakehead[0]][snakehead[1]].type) { case gamestrcut::null: map[snakehead[0]][snakehead[1]].type = gamestrcut::snakebody; map[snakehead[0]][snakehead[1]].time = snakehead[3]; break; case gamestrcut::snakebody: if (snakehead[2] != 0) goto end; break; case gamestrcut::food: map[snakehead[0]][snakehead[1]].type = gamestrcut::snakebody; map[snakehead[0]][snakehead[1]].time = snakehead[3]; ++snakehead[3]; for (unsigned long s = 0; s < sizeof(map) / sizeof(map[0]); ++s) { if (((gamestrcut*)map)[s].type == gamestrcut::snakebody) ++((gamestrcut*)map)[s].time; } for (unsigned long i = 0; i < width; ++i) { for (unsigned long j = 0; j < height; j++) { if (map[i][j].type == gamestrcut::snakebody) { ++map[i][j].time; } } } break; case gamestrcut::wood: goto end; break; default: break; } //刷新食物 { static char foodfresh; ++foodfresh; do { if (foodfresh <= 10) break; foodfresh = 0; unsigned long x = ((float)rand() / RAND_MAX) * width; unsigned long y = ((float)rand() / RAND_MAX) * height; if (map[x][y].type == gamestrcut::null) { map[x][y].type = gamestrcut::food; break; } } while (true); } //刷新蛇身 for (unsigned long i = 0; i < width; ++i) { for (unsigned long j = 0; j < height; j++) { if (snakehead[2] == 0) break; if (map[i][j].type == gamestrcut::snakebody) { --map[i][j].time; if (map[i][j].time <= 0) map[i][j].type = gamestrcut::null; } } } //屏幕输出 system("cls"); for (unsigned long i = 0; i < height; ++i) { char line[width + 3]; for (unsigned long j = 0; j < width; ++j) { switch (map[j][i].type) { case gamestrcut::null: line[j] = ' '; break; case gamestrcut::snakebody: line[j] = 'S'; break; case gamestrcut::food: line[j] = 'F'; break; case gamestrcut::wood: line[j] = 'W'; break; default: line[j] = '!'; break; } } line[width] = 0x0D; line[width + 1] = 0x0A; line[width + 2] = 0; printf(line); } } while (true);end: printf("你的分数是:%d\n",(long)snakehead[3] - 2); getchar(); }return我问了一下别的大佬他们说有可能是我前面就错了,但是不妨碍运行,麻烦云大佬们帮忙改一下,谢谢!(前面还有段代码因字数关系发不出来但肯定是对的)

网友回答:

程序出错的原因是因为

   printf("你的分数是:%d\n",(long)snakehead[3] - 2);

   getchar();

   }return

你的return 写错位置了

改为

   getchar();

   return 0;

}

程序就可以正常运行了


我来回答

相关问题