#include "stdafx.h"
#include "dos.h"
#include "iostream.h"
#include "stdio.h"
#include "string.h"
class CPlayer // the player class
{
public:
char RACE[8];
int HP;
int DEX;
int STR;
int AC;
int INT;
int MANA;
};
class CMonster // the monster class
{
public:
char NAME[10];
int HP;
int DEX;
int STR;
int AC;
int INT;
int MANA;
};
int main(int argc, char* argv[])
{
cout << "Creation step 1\n";
cout << "Choose a race\n\n";
cout << "1. Ogre\n";
cout << "2. Troll\n";
cout << "3. Human\n";
cout << "4. Elf\n";
int race;
cin >> race; // pick the race to be
CPlayer player; // make the player
player.RACE = "null";
player.HP = "10";
player.DEX = "10";
player.STR = "10";
player.AC = "5";
player.INT = "10";
player.MANA = "10";
switch (race)
{
case 1: // if ogre is chosen
cout<<"You are an Ogre.\n";
player.RACE = "1"; // make the player an ogre
break;
case 2: // if troll is chosen
cout<<"You are a Troll.\n";
player.RACE = "2"; // make the player a troll
break;
case 3: // if human is chosen
cout<<"You are a Human.\n";
player.RACE = "3"; // make the player a human
case 4: // if elf is chosen
cout<<"You are an Elf.\n";
player.RACE = "4"; // make the player an elf
default: // if anything else is entered
cout<<"That wasn't a choice!!!\n";
}
return 0;
}
Little help goes a long way
I am trying to make a very basic game. If i can get this begining part to work I should be able to run with it. As far as I can tell it should be working? I get errors when I compile though anyone know what I did wrong? Thank you for the fast response to my last post. I relize this is kind of the same thing.
Here is the errors on compiling.....
ompiling...
Game1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(55) : error C2440: '=' : cannot convert from 'char [5]' to 'char [8]'
There is no context in which this conversion is possible
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(56) : error C2440: '=' : cannot convert from 'char [3]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(57) : error C2440: '=' : cannot convert from 'char [3]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(58) : error C2440: '=' : cannot convert from 'char [3]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(59) : error C2440: '=' : cannot convert from 'char [2]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(60) : error C2440: '=' : cannot convert from 'char [3]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(61) : error C2440: '=' : cannot convert from 'char [3]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(69) : error C2440: '=' : cannot convert from 'char [2]' to 'char [8]'
There is no context in which this conversion is possible
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(77) : error C2440: '=' : cannot convert from 'char [2]' to 'char [8]'
There is no context in which this conversion is possible
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(85) : error C2440: '=' : cannot convert from 'char [2]' to 'char [8]'
There is no context in which this conversion is possible
C:\Program Files\Microsoft Visual Studio\MyProjects\Game1\Game1.cpp(91) : error C2440: '=' : cannot convert from 'char [2]' to 'char [8]'
There is no context in which this conversion is possible
Error executing cl.exe.
Game1.exe - 11 error(s), 0 warning(s) [/source]
[edited by - Maddawg on April 29, 2003 9:57:27 PM]
this is what''s causing the problem:
HP,DEX,STR etc are not strings, so you don''t use the quotes with them.
Change player.HP="10"; to player.HP=10; and it should work.
player.HP = "10";player.DEX = "10";player.STR = "10";player.AC = "5";player.INT = "10";player.MANA = "10";
HP,DEX,STR etc are not strings, so you don''t use the quotes with them.
Change player.HP="10"; to player.HP=10; and it should work.
Keep your questions about the same thing in one thread!
You should learn to interpret your compiler's error messages yourself. In this case, it's just saying that it can't convert do the conversions you're asking it to. You're trying to assign "10", which is a string, to an integer variable in several places. Fix that.
The "null" assignment is more interesting. The easiest way around that is to replace the
[edited by - micepick on April 29, 2003 10:04:44 PM]
You should learn to interpret your compiler's error messages yourself. In this case, it's just saying that it can't convert do the conversions you're asking it to. You're trying to assign "10", which is a string, to an integer variable in several places. Fix that.
The "null" assignment is more interesting. The easiest way around that is to replace the
char RACE[8]
with std::string RACE
. std::string is the C++ string class, which is much easier to use than the C-style char array.[edited by - micepick on April 29, 2003 10:04:44 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement