use*_*575 5 c++ compiler-errors
我在编译时收到此错误:
\n\nproject6.cpp:在函数\xe2\x80\x98int main()\xe2\x80\x99中:
\n\nproject6.cpp:187: 错误:输入末尾应有 \xe2\x80\x98}\xe2\x80\x99
\n\n但是,该行的 int main () 函数显然有一个结束括号,因此我很困惑为什么会收到此错误。我还检查了所有其他括号,发现没有一个未关闭的。任何帮助将非常感激!
\n\n#include <iostream>\n\nusing namespace std;\n\n\nvoid initRace(char grid[52][72])\n{ \n for(int r = 0; r < 52; r = r + 1)\n { for(int c = 0; c < 72; c = c + 1)\n { grid[r][0] = \'X\';\n grid[0][c] = \'X\';\n grid[r][71] = \'X\'; // border\n grid[51][c] = \'X\';\n }\n for(int c = 65; c <= 70; c = c + 1)\n { grid[51][c] = \'F\'; // finish line\n }\n }\n for(int r = 1; r <= 35; r = r + 1)\n { for(int c = 10; c <= 29; c = c + 1)\n { grid[r][c] = \'X\'; // first barrier\n }\n }\n\n for(int r = 16; r <= 50; r = r + 1)\n { for(int c = 40; c <=64; c = c + 1)\n { grid[r][c] = \'X\'; //second barrier\n }\n }\n\n for(int r = 1; r <= 50; r = r + 1)\n { for(int c =1; c <=9; c = c + 1)\n { grid[r][c] = \' \'; //first block of spaces\n }\n }\n\n for(int r = 36; r <= 50; r = r + 1)\n { for(int c =10; c <=29; c = c + 1)\n { grid[r][c] = \' \'; //second block of spaces\n }\n }\n\n for(int r = 1; r <= 50; r = r + 1)\n { for(int c =30; c <=39; c = c + 1)\n { grid[r][c] = \' \'; //third block of spaces\n }\n }\n\n for(int r = 1; r <= 15; r = r + 1)\n { for(int c =40; c <=64; c = c + 1)\n { grid[r][c] = \' \'; //fourth block of spaces\n }\n }\n\n for(int r = 1; r <= 50; r = r + 1)\n { for(int c =65; c <=70; c = c + 1)\n { grid[r][c] = \' \'; //fifth block of spaces\n }\n }\n grid[1][1] = \'O\';\n}\n\nvoid printRace(char grid[52][72])\n{ for (int i = 0 ; i < 52; i = i + 1)\n { for (int j = 0 ; j < 72; j = j + 1)\n { cout << grid[i][j] << " ";\n }\n cout << endl;\n }\n\n}\n\nint main(void)\n{ char grid[52][72];\n\n initRace(grid);\n\n\n int xAcceleration;\n int yAcceleration;\n int xVelocity = 0;\n int yVelocity = 0;\n int xPosition = 1;\n int yPosition = 1;\n\n\n for(int i = 1; i < 100; i = i + 1)\n { printRace(grid);\n cout << "Horizontal and vertical acceleration (-1,0,1): ";\n cin >> xAcceleration;\n cin >> yAcceleration; \n\n if((xAcceleration != 0) && (xAcceleration != 1) && (xAcceleration != -1))\n { if(i == 1)\n { cout << "Crashed after " << i << " second" << endl;\n }\n else\n { cout << "Crashed after " << i << " seconds" << endl;\n printRace(grid);\n i = 500;\n }\n\n if((yAcceleration != 0) && (yAcceleration != 1) && (yAcceleration != -1))\n { printRace(grid);\n if(i == 1)\n { cout << "Crashed after " << i << " second" << endl;\n }\n else\n { cout << "Crashed after " << i << " seconds" << endl;\n }\n i = 500;\n }\n\n xVelocity = xVelocity + xAcceleration;\n yVelocity = yVelocity + yAcceleration;\n\n xPosition = xPosition + xVelocity;\n yPosition = yPosition + yVelocity;\n\n\n if((xPosition >= 10) && (xPosition <=29) && (yPosition >= 1) && (yPosition<= 35))\n { grid[yPosition][xPosition] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; // crashed into first barrier\n i = 500;\n }\n\n if((xPosition >= 40) && (xPosition <= 64) && (yPosition >= 16) && (yPosition <= 50))\n { grid[yPosition][xPosition] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; // crashed into second barrier\n i = 500;\n }\n\n if(xPosition <= 0) //crashed into left border\n { grid[yPosition][0] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; \n i = 500; \n }\n\n if(yPosition <= 0) //crashed into top border\n { grid[0][xPosition] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; \n i = 500; \n }\n\n if(xPosition >= 71) //crashed into right border\n { grid[yPosition][71] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; \n i = 500; \n }\n\n if((yPosition >= 51) && (xPosition >= 1) && (xPosition <= 39)) //crashed into bottom border\n { grid[51][xPosition] = \'O\';\n printRace(grid);\n cout << "Crashed after " << i << " seconds" << endl; \n i = 500; \n }\n\n if((xPosition >= 65) && (xPosition <= 70) && (yPosition >= 51)) // crossed finish line\n { grid[51][xPosition] = \'O\';\n printRace(grid);\n cout << "Finished after " << i << " seconds" << endl;\n i = 500;\n }\n\n\n grid[yPosition][xPosition] = \'O\';\n\n\n }\n\n return 0;\n\n} // THIS IS LINE 187\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
140181 次 |
| 最近记录: |