Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 3rd, 2005, 7:19 PM   #1
glopal
Newbie
 
Join Date: May 2005
Location: St. Andrews, Manitoba, Canada
Posts: 9
Rep Power: 0 glopal is on a distinguished road
Function Calls and Errors!

Hey all yal, Im pretty new to programming in C++ so be patient with me.

I get these errors:

--------------------Configuration: battle - Win32 Debug--------------------
Compiling...
battle.cpp
Linking...
battle.obj : error LNK2001: unresolved external symbol "int __cdecl battle(char,int,int)" (?battle@@YAHDHH@Z)
battle.obj : error LNK2001: unresolved external symbol "int __cdecl randomfoe(char,int,int)" (?randomfoe@@YAHDHH@Z)
Debug/battle.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

battle.exe - 3 error(s), 0 warning(s)

With this code:
#include <iostream.h>
#include <windows.h>
#include <stdlib.h>
#include <time.h>


//Prototyping-------------
int battle(char,int,int);
int randomfoe(char,int,int);

//------------------------

int main()
{
	char foename[15] = "";
	int foelvl = 0; 
	int map = 1;

	battle(foename[15],foelvl,map);
	return 0;

}

//////////////////////////////////////////////////////////

int battle(char foename[],int foelvl,int map)
{
	randomfoe(foename[15],foelvl,map);
	cout << "You are fighting a LVL "<< foelvl <<" " <<foename <<endl;
	return 0;


}

int randomfoe(char foename[],int foelvl,int map)
{
	short randfoelvl = 0;

	short randfoename = 0; 

	srand(time(NULL));
	
	randfoename = rand() + 1 % (3 - 1 + 1); 
	randfoelvl = rand() + 1 % (100 -1 + 1);

	
//RANDOM ENEMY NAME-------------------------------
	if (map = 1) 
	{
		if (randfoename == 1)
			foename = "Killer Mole";
		if (randfoename == 2)
			foename = "Crazed Bat";
		if (randfoename == 3)
			foename = "Giant Worm";
	
	}


	
//RANDOM ENEMY LEVEL------------------------------
	
	if (map = 1) 
	{
		if (randfoelvl >=1 && randfoelvl <=30)
			foelvl = 1;
		if (randfoelvl >=31 && randfoelvl <=80)
			foelvl = 2;
		if (randfoelvl >=81 && randfoelvl <=100)
			foelvl = 3;

	}

	return foelvl;

}

WHY? I personally think it has to do with me calling the randomfoe function from the battle function. How do I fix it?

Last edited by glopal; May 3rd, 2005 at 8:23 PM.
glopal is offline   Reply With Quote
Old May 3rd, 2005, 9:00 PM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
change this:
battle(foename[15],foelvl,map);

to this:
battle(foename,foelvl,map);

and change this:
int battle(char,int,int);

to this:
int battle(char[], int, int);

then do the same for the other function.
uman is offline   Reply With Quote
Old May 3rd, 2005, 9:06 PM   #3
glopal
Newbie
 
Join Date: May 2005
Location: St. Andrews, Manitoba, Canada
Posts: 9
Rep Power: 0 glopal is on a distinguished road
Thx no more errors, but now I have a new problem.

When I call the randomfoe function from the battle function it doesnt seem to work. When I execute, I shows LVL 0, and nothing for the name. Help please!
glopal is offline   Reply With Quote
Old May 3rd, 2005, 9:33 PM   #4
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
C++ passes variables by value. If you don't know what this means, and whatever reference you're using to learn C++ doesn't explain it, you need to throw it away and get a new one.
uman is offline   Reply With Quote
Old May 4th, 2005, 3:45 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
or in other words when passing a variable by value the original value of the variable does not change so when you pass a 2 to the function the variable when it returns from the funcition will still be 2.

This is why you have a return value from a function like you have it returning a int. Therefore you have to assign a variable to catch this int that is being returned(well you dont have to but its a good idea if returning somehting meaningful)

so chenge it from

randomfoe(foename[15],foelvl,map);

to

foelvl = randomfoe(foename[15],foelvl,map);

jhope this helps a little
Berto is offline   Reply With Quote
Old May 4th, 2005, 11:09 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Change char foename[15] in the function parameter declarations to char *foename, and char to char * in the prototypes at the top. Then pass foename, not foename[15] to the functions.
__________________
Me :: You :: Them

Last edited by Ooble; May 4th, 2005 at 11:12 AM.
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC