functions not working.

Hello. I'm working on a simple game. I know this isn't advanced, or proper way to do this, but I'm just learning functions. That's where I need the help. Could you go over this code, and point out where the errors are?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include <iostream>
#include <string>
using namespace std;
int Hero_Health, Damage, Remaining_Health;
int battle (int Hero_Health, int Damage int Remaining_Health);
int main ()
{
	string Hero_Name;
	string Answer;
	cout << "What is your hero's name?: ";
	getline(cin, Hero_Name);
	cout << "Welcome " << Hero_Name << " You are walking in the hills of Talbis when you come across a vicious goblin. Do you wish to battle the creature, or run away? ";
	getline(cin, Answer);
	if (Answer == "battle him" || Answer == "fight him" || Answer == "fight" || Answer == "battle" || Answer == "f" || Answer == "b")
	{
		battle(100, 50, );
		cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;
	}
	else
	{
	cout << "You decide to run into the distance";
	}
	return 0;
}
	int battle ( int Hero_Health, int Damage)
	{
		Hero_Health - Damage = Remaining_Health;
		return Remaining_Health;
	}

int battle (int Hero_Health, int Damage int Remaining_Health);
Missing comma somewhere.

battle(100, 50, );
Doesn't match the function declaration's prototypes.

int battle ( int Hero_Health, int Damage)
Read ""

Hero_Health - Damage = Remaining_Health;
Change the statement a bit.
hay, thanks. I've got some of the problems cleared up, but now I'm getting an error thats saying something isn't getting a valvue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include <iostream>
#include <string>
using namespace std;
int Hero_Health, Damage, Remaining_Health;
int battle (int Hero_Health, int Damage);
int main ()
{
	string Hero_Name;
	string Answer;
	cout << "What is your hero's name?: ";
	getline(cin, Hero_Name);
	cout << "Welcome " << Hero_Name << " You are walking in the hills of Talbis when you come across a vicious goblin. Do you wish to battle the creature, or run away? ";
	getline(cin, Answer);
	if (Answer == "battle him" || Answer == "fight him" || Answer == "fight" || Answer == "battle" || Answer == "f" || Answer == "b")
	{
		battle(100, 50);
		cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;
	}
	else
	{
	cout << "You decide to run into the distance";
	}
	return 0;
}
	int battle ( int Hero_Health, int Damage)
	{
		Hero_Health - Damage = Remaining_Health;
		return Remaining_Health;
	}
You have global variables Hero_Health, Damage, and Remaining_Health, but those aren't the same values being used in your function. Line 28 is still broken.
Global variables can't be used, and given a value anywhere within the program? I thought that Hero_Health, and Damage would be given values here.

 
battle(100, 50);


and then I thought that Remaining_Health would be given it's value here.

 
Hero_Health - Damage = Remaining_Health;


and then returned to here.

 
cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;


Hero_Health - Damage = Remaining_Health; should be Remaining_Health = Hero_Health - Damage;
No, that is not how functions/values work. Re-read up on functions:
http://www.cplusplus.com/doc/tutorial/functions/
Thank Bazzy, works fine , and it should have been obviouse to me that it should have been written like that.
Topic archived. No new replies allowed.