RPG coding help

I'm not sure what the meaning of

Line 53: [Error] invalid operands of types 'int' and 'int()' to binary 'operator-'

is... I'm a beginner and I'm just trying to make a simple RPG style text game.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  // Basic Instance

#include <cstdlib>
#include <iostream>

using namespace std;

char classchoice;

int Chooseclass()
{
	cout << "Choose your class... 1=Rogue, 2=Warrior, or 3=Mage?" << endl;
	cin >> classchoice;
	if(classchoice == 1);
	{
		cout << "You love fighting from the darkness, you are granted a dagger! \nObtained a Wooden Dagger!" << endl;
	}
}

int Level = 1;
int equipslot;
int attack;
int damage()
{
	int damage = 5;
	if(classchoice == 1)
	{
		damage = damage + 1;
	}
}
int Orchealth = 50;

int WoodendaggerLv1()
{
	cout << "Wooden Dagger \nBase Damage: 5 \nLevel 1 \n \nYour Level: " << Level << endl;
	if (Level >= 1)
	{
		cout << "Press 1 to equip" << endl;
		cin >> equipslot;
		if (equipslot = 1);
		{
			cout << "You equip the Iron Sword" << endl;
		}
	}	
}

int Instance()
{
	cout << "An Orc Lv.1 has appeared! \nPress 1 to attack" << endl;
	cin >> attack;
	if (attack = 1);
	{
		cout << "You deal " << damage << " damage \nOrc Health: " << Orchealth - damage << endl;
		Orchealth = Orchealth - damage;
		if (Orchealth < 0)
		{
			cout << "You killed the Orc! 5 EXP gained!" << endl;
			return 0;
		}
		else(Orchealth >0);
		{
			Instance();
		}
	}
}


int main()
{
	Chooseclass();
	WoodendaggerLv1();
	Instance();
	return 0;
}
your if statement should be: if(attack == 1) this compares the option and alllows the statement to continue

i would suggest if(Orchealth < 0) to be if(Orchealth <= 0) in case it does reach exactly 0

within your main, i would check to see if the orc's health is <= 0
int main()
{
//code
while(Orchealth > 0)
{
Instance();
}
//code
}
On line 53 'damage' is not a variable, but a function that returns a int, so you're trying to do 'Orchealth' (int) - 'damage' (int()).
By the way, damage() doesn't return anything. Add return damage at the end of its body.
Thank you so much for your replies! I changed the line 23 to int ad() instead of int damage() but now damage isn't defined in the scope...
It means the compiler can't find something called 'damage' that it can access from that point of the code.
If you change 'damage' to 'ad' it's natural that the compiler doesn't find 'damage' anymore.
You can either define a variable inside Instance() and store the value of the damage done to use it later
1
2
3
 int dmg = damage();
//...
cout << "You deal " << dmg << " damage \nOrc Health: " << Orchealth - dmg << endl;
or directly use the return value of the function for the calculation
 
cout << "You deal " << damage() << " damage \nOrc Health: " << Orchealth - damage() << endl;


The core of the problem was that if you write damage you're referring to a variable called 'damage'; if you write damage() you're referring to a function called 'damage'.
Change 'damage' to 'ad' if you like that name better.
Thanks, you're awesome. Like I said I started today and just need to figure a few things out. Thanks so much.
Topic archived. No new replies allowed.