Combat system

hey... i'm working on a combat system
and getthis error....

Error 1 error C2446: '==' : no conversion from 'const char *' to 'int' c:\users\www\documents\visual studio 2008\projects\combatsystem\combatsystem\combatx.cpp 30 CombatSystem
and this is my code....
Last edited on
How am I supposed to know which line is line 30 if you don't post all of the code?
How am I supposed to guess which line is causing the error if I can't read your code?

Use [code] [/code] tags, and then I will read it.
sorry
Last edited on
sorry guys... ill post the whole code... my bad

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
75
76
77
78

/* Combat System */

#include <iostream>
#include <vector>
#include <string>
#include <windows.h>
using namespace std;



// main game loop
void GameLoop();

// Attack Damage
int userDmg = 5;
int enemy1Dmg = 10;

// Health Guage
int userHealth = 100;
int enemy1Health = 40;


void main() 
{
	cout << " you arrive on Omega and are confronted by a mercenary and tells you to leave or fight....what will you do...:" << endl;
	cout <<"Press A to attack Press L to leave" << endl;

	char command;
	cin >> command;
	if(command == "A")
	{
		GameLoop();
	}
	else 
	{
		cout <<"You Better Run..."<< endl;
	
	}

}
void hitEnemy(int Amt)
{
	cout << " You shoot the Merc in the leg for:" << Amt << endl;
	enemy1Health -= Amt;
	cout << "Merc health" << enemy1Health << endl;
	Sleep(3500);
}

void Enemyhit(int Amt)
{
	cout << " The Merc Shoots you in the leg:" << Amt << endl;
	userHealth -= Amt;
	cout << " Remaining Health:" << userHealth <<endl;
	Sleep(3500);
}
void GameLoop()
{
	// Make sure the game is running
	while(true)
	{
		if(enemy1Health <= 0)
		{
			cout <<"The Merc is dead..." << endl;

			return;
		}
if(userHealth <=0)
{
	cout <<"....::YouR DeaD::.....:" << endl;

	return;
}

hitEnemy(userDmg);
Enemyhit(enemy1Dmg);
	}
}
Thank you. As it happens the error is on line 31, here: if(command == "A")

You seem to misunderstand the difference between a character literal and a string literal. A character literal is a single character and can be stored in an int; with char being a 1 byte integer used for storing single ASCII characters. A character literal is a single character enclosed in inverted commas: ' and '. A string literal is a group (or string) of characters enclosed in quotation marks: " and ".

What you've done is put a character literal in quotation marks instead of using inverted commas. Because of that, it's like you're comparing a const char* (which is a C string) with a char. A char can't be compared with a "C-string", so you get that error.
so if i make it string command i wont get the error??
sorry man im a lil new to c++ so i'm kinda having a hard time with this
Last edited on
YES it worked thank you i appreciate that..
No if you make it either:
1
2
3
4
5
6
7
8
9
10
11
12
char command;
cin >> command;
if(command == 'A')
...


// OR

std::string command;
cin >> command;
if(command == "A")
...
Topic archived. No new replies allowed.