Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected ‘}’ at end of input -- when there is one [closed]

I am getting this error when compiling:

project6.cpp: In function ‘int main()’:

project6.cpp:187: error: expected ‘}’ at end of input

However, there is clearly an end bracket to my int main () function at that line, so I am confused as to why I am getting this error. I also checked all of my other brackets and found none that were not closed. Any help would be much appreciated!

#include <iostream>

using namespace std;


void initRace(char grid[52][72])
{  
   for(int r = 0; r < 52; r = r + 1)
   {  for(int c = 0; c < 72; c = c + 1)
      {  grid[r][0] = 'X';
         grid[0][c] = 'X';
         grid[r][71] = 'X'; // border
         grid[51][c] = 'X';
      }
      for(int c = 65; c <= 70; c = c + 1)
      {  grid[51][c] = 'F';         // finish line
      }
   }
   for(int r = 1; r <= 35; r = r + 1)
   {  for(int c = 10; c <= 29; c = c + 1)
      {  grid[r][c] = 'X';             // first barrier
      }
   }

   for(int r = 16; r <= 50; r = r + 1)
   {   for(int c = 40; c <=64; c = c + 1)
       {  grid[r][c] = 'X';             //second barrier
       }
   }

   for(int r = 1; r <= 50; r = r + 1)
   {   for(int c =1; c <=9; c = c + 1)
       {  grid[r][c] = ' ';             //first block of spaces
       }
   }

   for(int r = 36; r <= 50; r = r + 1)
   {   for(int c =10; c <=29; c = c + 1)
       {  grid[r][c] = ' ';             //second block of spaces
       }
   }

   for(int r = 1; r <= 50; r = r + 1)
   {   for(int c =30; c <=39; c = c + 1)
       {  grid[r][c] = ' ';             //third block of spaces
       }
   }

   for(int r = 1; r <= 15; r = r + 1)
   {   for(int c =40; c <=64; c = c + 1)
       {  grid[r][c] = ' ';             //fourth block of spaces
       }
   }

   for(int r = 1; r <= 50; r = r + 1)
   {   for(int c =65; c <=70; c = c + 1)
       {  grid[r][c] = ' ';             //fifth block of spaces
       }
   }
   grid[1][1] = 'O';
}

void printRace(char grid[52][72])
{  for (int i = 0 ; i < 52; i = i + 1)
   {  for (int j = 0 ; j < 72; j = j + 1)
      {  cout << grid[i][j] << " ";
      }
      cout << endl;
   }

}

int main(void)
{  char grid[52][72];

   initRace(grid);


   int xAcceleration;
   int yAcceleration;
   int xVelocity = 0;
   int yVelocity = 0;
   int xPosition = 1;
   int yPosition = 1;


   for(int i = 1; i < 100; i = i + 1)
   {  printRace(grid);
      cout << "Horizontal and vertical acceleration (-1,0,1): ";
      cin >> xAcceleration;
      cin >> yAcceleration; 

      if((xAcceleration != 0) && (xAcceleration != 1) && (xAcceleration != -1))
      {  if(i == 1)
         {  cout << "Crashed after " << i << " second" << endl;
         }
         else
         {  cout << "Crashed after " << i << " seconds" << endl;
         printRace(grid);
         i = 500;
      }

      if((yAcceleration != 0) && (yAcceleration != 1) && (yAcceleration != -1))
      {  printRace(grid);
         if(i == 1)
         {  cout << "Crashed after " << i << " second" << endl;
         }
         else
         {  cout << "Crashed after " << i << " seconds" << endl;
         }
         i = 500;
      }

      xVelocity = xVelocity + xAcceleration;
      yVelocity = yVelocity + yAcceleration;

      xPosition = xPosition + xVelocity;
      yPosition = yPosition + yVelocity;


      if((xPosition >= 10) && (xPosition <=29) && (yPosition >= 1) && (yPosition<= 35))
      {  grid[yPosition][xPosition] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;        // crashed into first barrier
         i = 500;
      }

      if((xPosition >= 40) && (xPosition <= 64) && (yPosition >= 16) && (yPosition <= 50))
      {  grid[yPosition][xPosition] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;        // crashed into second barrier
         i = 500;
      }

      if(xPosition <= 0)            //crashed into left border
      {  grid[yPosition][0] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;      
         i = 500;                               
      }

      if(yPosition <= 0)            //crashed into top border
      {  grid[0][xPosition] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;      
         i = 500; 
      }

      if(xPosition >= 71)           //crashed into right border
      {  grid[yPosition][71] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;      
         i = 500; 
      }

      if((yPosition >= 51) && (xPosition >= 1) && (xPosition <= 39))     //crashed into bottom border
      {  grid[51][xPosition] = 'O';
         printRace(grid);
         cout << "Crashed after " << i << " seconds" << endl;      
         i = 500; 
      }

      if((xPosition >= 65) && (xPosition <= 70) && (yPosition >= 51))      // crossed finish line
      {  grid[51][xPosition] = 'O';
         printRace(grid);
         cout << "Finished after " << i << " seconds" << endl;
         i = 500;
      }


      grid[yPosition][xPosition] = 'O';


   }

   return 0;

}      // THIS IS LINE 187
like image 273
user1757575 Avatar asked Feb 18 '23 12:02

user1757575


1 Answers

One of your else blocks does not have a closing brace... Look below:

     else
     {  cout << "Crashed after " << i << " seconds" << endl;
     printRace(grid);
     i = 500;

Due to this, the total number of closing braces is not equal to the opening braces, hence the error.

like image 86
Aamir Avatar answered Mar 05 '23 14:03

Aamir