RUSES
Would you like to react to this message? Create an account in a few clicks or log in to continue.
April 2024
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
2930     

Calendar Calendar


function call errors, HELP!

2 posters

Go down

function call errors, HELP! Empty function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:13 am

Hi guys. I keep getting an error in my function call for:
int movechecky ( x , y, dir, maze1[19][23]);

it wants me to put brackets around the x. i think it doesn't want to accept all four function parameters.
i put my functions in their own header file, and the prototypes in another header (with a #pragma once), then include both these header files in my main.cpp

the prototype is:
int movechecky (int x, int &y, int dir, int maze1[19][23]);

all the relevant code is right here. it's all lumped into one, so needs to be separated into header & cpp files before it can be compiled. i put comments in where each file starts.

http://pastie.org/private/avz8kptqudwxzzqhzzzdw

thanks =)

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:21 am

Change int movechecky ( x , y, dir, maze1[19][23]);

to

int movechecky ( int , int, int, int[][]);

failing that:

int movechecky ( int x, int y, int dir, int maze1[19][23]);

You are defining the function parameters by variable names instead of by their types

*goes to actually read code just in case this doesn't work*
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:23 am

Should work, one problem is there's no function for movecheckx()

Code:
//movecheck.h :

#pragma once
 //this needs to be in movecheck
int movechecky (int x, int &y, int dir, int maze1[19][23]);
int movecheckx (int &x, int y, int dir, int maze1[19][23]);

int movechecky (int x, int &y, int dir, int maze1[19][23])
{
   switch (dir)
   {
   case 'n':
      {
         if (maze1[x][y+1] = 0)
         {
            break;
            return -1;
         }
         else
            if (maze1[x][y+1] = 1)
         {
            y++;
         }
      }
      break;
   case 's':
      {
         if (maze1[x][y-1] = 0)
         {
            break;
            return -1;
         }
         else
            if (maze1[x][y-1] = 1)
         {
            y--;
         }
      }
      break;
   default :
      break;
   }

   return y;
}

Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:24 am

haven't gotten around to movecheckx just yet. was going to just copy paste the movechecky and edit it once i got movechecky working.
Thanks very much, I'll give it a try =)

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:24 am

And you need to #include movecheck.h - about to compile and test it in a sec just to see though
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:25 am

Haha oops! I deleted it out earlier to copy some other stuff to someone else and never put it back...

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:28 am

Okay solved Smile

movecheck.h (you need to create movecheckx()
Code:
int movechecky (int x, int &y, int dir, int maze1[19][23]);
int movecheckx (int &x, int y, int dir, int maze1[19][23]);

int movechecky (int x, int &y, int dir, int maze1[19][23])
{
   switch (dir)
   {
   case 'n':
      {
         if (maze1[x][y+1] = 0)
         {
            break;
            return -1;
         }
         else
            if (maze1[x][y+1] = 1)
         {
            y++;
         }
      }
      break;
   case 's':
      {
         if (maze1[x][y-1] = 0)
         {
            break;
            return -1;
         }
         else
            if (maze1[x][y-1] = 1)
         {
            y--;
         }
      }
      break;
   default :
      break;
   }

   return y;
}

int movecheckx (int &x, int y, int dir, int maze1[19][23])
{
   return 0;
}

main.cpp
Code:

#include <iostream>
#include <string>
#include <limits>
#include "movecheck.h"
using namespace std;

//note to self: array[y][x] - gives 'y' arrays (rows) with 'x' elements (columns) in each.

int main ()
{
   int maze1[19][23] = {
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0},
{0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0},
{0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0},
{0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0},
{0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0},
{0,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,0,1,0,1,0},
{0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0},
{0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{0,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,0,0},
{0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0},
{0,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,0},
{0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0},
{0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1,0},
{0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0},
{0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,3},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};

   cout <<
      "###############################################################################" <<endl <<
      "#                                                                            #" <<endl <<      
      "#                                  Written by                                #" <<endl <<
      "#                                Victoria Lawson                            #" <<endl <<
      "#                                  YG000976                                  #" <<endl <<
      "#                            @ Univeristy of Reading                          #" <<endl <<
      "#                                                                            #" <<endl <<
      "#                              WELCOME TO MY MAZE                            #" <<endl <<
      "#                                                                            #" <<endl <<
      "###############################################################################" <<endl <<
      "Press enter to start";
   cin.ignore(numeric_limits <streamsize> ::max(), '\n' );
   fflush(stdin);
   cout << string(50, '\n');

   int x=1, y=0;

   cout << "->You find yourself at the start of what appears to be a maze." << endl <<
      "There are hedges on either side, and to the north, behind you, is what used to " << endl << "be the entrance." <<
      " You attempt to open the door." << endl <<
      "Though you put all your strength into it, the door has been sealed off and you " << endl << "cannot go back."
      "The only way, it seems, is forwards." << endl << endl <<
      "Press 'S' to go south" << endl << endl << "->";

   char dir;
   cin >> dir;


   if (dir == 'n' || dir == 's' || dir == 'N' || dir == 'S')
   {
      movechecky ( x ,  y,  dir,  maze1);
   }
   else
      if (dir == 'e' || dir == 'w' || dir == 'W' || dir == 'E')
   {
       movecheckx ( x,  y,  dir,  maze1);
   }


   char dummy;
   cin >> dummy; // keeps cmd window open
}
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:29 am

It still refuses to compile =(

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:31 am

What's the error? cos it's compiling for me :S
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:33 am

Ugh. never mind. Tried editing my current solution and it failed.

Created a new one using only your code and it was fine. I have no idea where the problem was in mine, but this works fine.
Thanks very much =)

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:37 am

'Thanks very much' doesn't really cut it.
I was getting so damn stressed about it, because I couldn't figure the problem myself. The relief is unbelieveable haha!

<3

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 10:48 am

No problem Very Happy I'm like a code machine provided people say thanks and I'm not doing the same thing repeatedtly (like the algorithms cw ._.)
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 10:50 am

xD oh god. I actually understood algorithms myself in the end. Explaining it to people on fb was not fun!

Now I just need to make movecheck WORK. Tested it using a valid movement. Seems my errorcheck is overzealous..... xD

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 11:02 am

Ah your maze check isn't working because in the if statements you are doing

if (maze1[x][y-1] = 0)

instead of

if (maze1[x][y-1] == 0)
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 11:04 am

...God DAMNIT.
xD
I am useless sometimes! Thanks again Razz

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 11:12 am

Omg. Every time I fix something, another thing breaks. Error code LNK1104

Googled it and found something about changing the Additional Dependencies under Configuration Properties -> Linker -> Input.
It said to put quotes around a particular file directory, but I don't have that directory in the box. I am lost.

http://stackoverflow.com/questions/133698/why-does-fatal-error-lnk1104-cannot-open-file-c-program-obj-occur-when-i-c is the page i was looking at.

Additional dependencies are:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

Sorry! I came on here to ask about one thing, and now I've got you fixing all my errors.... I'll pay you back, promise.



VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 11:19 am

Copied every source file over into a new solution and it works fine.
I wonder where the fuck that error came from....

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Alex Tue Mar 06, 2012 11:33 am

LNK1104 sometimes crops up for me, it's annoying, I forgot how I get rid of it, but at least you got it sorted Smile
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  VicVic Tue Mar 06, 2012 11:33 am

=)

VicVic

Posts : 17
Join date : 2012-02-28

Back to top Go down

function call errors, HELP! Empty Re: function call errors, HELP!

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum