You are viewing our Forum Archives. To view or take place in current topics click here.
[C++] HELP! 1 Unresolved External +REP
Posted:

[C++] HELP! 1 Unresolved External +REPPosted:

-Deano
  • Spooky Poster
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
I know it's a longshot that anyone will bother looking through this but I cannot find the error.
You guys know what it's like, there will be one obvious thing that I'm missing and someone else will find it instantly.

I've narrowed it down to these two functions but cannot for the life of me find it.

I WILL +REP LOADS WHOEVER FINDS THE ERROR - This is driving me insane.

void newGame()
{
   string grid[8][8];      /* Create array to store colours in. The array stores the colour for the crystal at the [X][Y] coordinate */
   int iColour = 0;      /* Holds the random number and is used to calculate what colour the crystal is */
   int tempiColour = 0;   /* Holds last number generated to not have duplicates */
   string colour = "";      /* Holds colour to write to the grid struct */
   for (int i = 0; i < 8; i++)
   {
      for (int j = 0; j < 8; j++)
      {
         do
         {
            iColour = rand() % 6;
         } while (tempiColour == iColour);
         switch (iColour)
         {
            case 0:
            {
               colour = "cyan";
               break;
            }
            case 1:
            {
               colour = "green";
               break;
            }
            case 2:
            {
               colour = "purple";
               break;
            }
            case 3:
            {
               colour = "red";
               break;
            }
            case 4:
            {
               colour = "yellow";
               break;
            }
            case 5:
            {
               colour = "white";
               break;
            }
         }
         grid[i][j] = colour;
      }
   }
   game(grid);
   return;
}

void game(string grid)
{
   bool exit = false;  /* Create exit bool to trigger when the player wants to exit the game */
   int playerX = 0;    /* Stores player's chosen x coordinate */
   int playerY = 0;    /* Stores player's chosen u coordinate */
   clear();
   do
   {
      do
      {
         // print grid
         printf("X: ");  /* Ask for X-coordinate in grid */
         scanf_s("%d", &playerX);  /* Assign entered character to playerX */
         printf("Y: ");
         scanf_s("%d", &playerY);
         printf("%d, %d", playerX, playerY);

         if (playerX == ESC || playerY == ESC)  /* If the character for either is ESC */
         {
            exit = true;
            
         }
         else
         {
            printf("Direction of swap?\n");
            bool validMove = false;
            do
            {
               switch (_getch()) /* Get user input */
               {
               case KP8: /* If input is Keypad_8 */
               {
                  printf("You swapped the crystal upwards.\n");
                  validMove = true;
                  break;
               }
               case KP2: /* If input is Keypad_2 */
               {
                  printf("You swapped the crystal downwards.\n");
                  validMove = true;
                  break;
               }
               case KP4: /* If input is Keypad_4 */
               {
                  printf("You swapped the crystal to the left.\n");
                  validMove = true;
                  break;
               }
               case KP6: /* If input is Keypad_6 */
               {
                  printf("You swapped the crystal to the right.\n");
                  validMove = true;
                  break;
               }
               default:
               {
                  printf("That was an invalid movement.\n");
                  validMove = true;
                  break;
               }
               }
            } while (validMove == false);
         }
         wait();
      } while (playerX <= -1 || playerX >= 9 || playerY <= -1 || playerY >= 9);
   } while (exit != true);  /* Repeat the game loop until the player wants to exit the game */
   return;  /* Return to the main menu if the game loop is exited */
}
#2. Posted:
The-Monstrosity
  • Resident Elite
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 219
Reputation Power: 8
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 219
Reputation Power: 8
void newGame() <----- just put this????
#3. Posted:
-Deano
  • PC Master Race
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
twerkgamer wrote void newGame() <----- just put this????


Nah, I've already got my prototype earlier in my code. I dont want to be pasting about 700 lines on here though
#4. Posted:
The-Monstrosity
  • Resident Elite
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 219
Reputation Power: 8
Status: Offline
Joined: Dec 28, 201310Year Member
Posts: 219
Reputation Power: 8
-Deano wrote
twerkgamer wrote void newGame() <----- just put this????


Nah, I've already got my prototype earlier in my code. I dont want to be pasting about 700 lines on here though


I dont know then dude sorry, i only experianced python and html
#5. Posted:
-Deano
  • Spooky Poster
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
twerkgamer wrote
-Deano wrote
twerkgamer wrote void newGame() <----- just put this????


Nah, I've already got my prototype earlier in my code. I dont want to be pasting about 700 lines on here though


I dont know then dude sorry, i only experianced python and html


Thanks for the attempt anyway :satisfied:
#6. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Lurking in the background again, the only issue i see out of those functions is that "exit" is actually a C++ Function, you are setting as a local Boolean, maybe worth changing as that could be an issue....

Their is no default case on your first switch statement, but that shouldn't cause a compile error, only a possible runtime error....

I am assuming newGame is called from your Main Method (if you showed all the code...) so the return statement at the end of the newGame Method is also valid....

Can't see any other issues..... so I am a bit stumped at the moment.
#7. Posted:
Dovashin
  • Prospect
Status: Offline
Joined: Jul 10, 20149Year Member
Posts: 624
Reputation Power: 33
Status: Offline
Joined: Jul 10, 20149Year Member
Posts: 624
Reputation Power: 33
I don't understand the issue. Is it not compiling? I checked over the code a few times and saw no syntax errors. I'm going to test out somethings with the code. I'll run some diagnostics and such. I will also consult with my actual teacher if necessary as this is also driving me insane.
#8. Posted:
HCIM
  • Wise One
Status: Offline
Joined: Oct 17, 201211Year Member
Posts: 594
Reputation Power: 23
Status: Offline
Joined: Oct 17, 201211Year Member
Posts: 594
Reputation Power: 23
default:
      {
       printf("That was an invalid movement.\n");
       validMove = true;
       break;
      }
      }
     } while (validMove == false);


I quickly glanced at the code and saw after your default breaks it has two }.
I checked to see if all brackets are there and they are - try deleting the extra bracket.

This could be what is giving your error. It causes your do/while loop to end giving the compilation error - your while loop is still exists.
#9. Posted:
-Deano
  • PC Master Race
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201013Year Member
Posts: 5,238
Reputation Power: 532
Kiln wrote
default:
      {
       printf("That was an invalid movement.\n");
       validMove = true;
       break;
      }
      }
     } while (validMove == false);


I quickly glanced at the code and saw after your default breaks it has two }.
I checked to see if all brackets are there and they are - try deleting the extra bracket.

This could be what is giving your error. It causes your do/while loop to end giving the compilation error - your while loop is still exists.


The double }} is to close of the last case statement and the entire switch altogether.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.