Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: gimmpy224
Im trying to BEGIN writing a text based game of some sort, and right now im just trying to figure out how im wanting to code it.
when i compile the following project, it says i have an error that says :
c:\program files\microsoft visual studio\alchemyst.cpp(1) : fatal error C1083: Cannot open include file: 'MonStats.h': No such file or directory
Error executing cl.exe.
the header file im using is :{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 #include <iostream.h>\par
#include <string.h>\par
\par
class Monster // base class\par
\{\par
public:\par
\tab virtual void PrintStats(void);\par
\tab Monster(int HP, int Strength, int Attack, int Defense, int Level , int MaxDamage, int MinDamage);\par
\tab ~Monster(void);\par
protected:\par
\tab int hp;\par
\tab int strength;\par
\tab int attack;\par
\tab int defense;\par
\tab int level;\par
\tab int maxDamage;\par
\tab int minDamage;\par
\};\par
\par
// Set all ^^^ to zero.\par
Monster::Monster(int HP, int Strength, int Attack, int Defense, int Level , int MaxDamage, int MinDamage)\par
\{\par
\tab hp = HP;\par
\tab strength = Strength;\par
\tab attack = Attack;\par
\tab defense = Defense;\par
\tab level = Level;\par
\tab maxDamage = MaxDamage;\par
\tab minDamage = MinDamage;\par
\}; \par
\par
Monster::~Monster(void)\par
\{\par
\tab hp = 0;\par
\tab strength=0;\par
\tab attack = 0;\par
\tab defense = 0;\par
\tab level = 0;\par
\tab maxDamage = 0;\par
\tab minDamage = 0;\par
\par
\};\par
\par
void Monster::PrintStats()\par
\{\par
\tab cout << "Hit Points = " << hp<<endl;\par
\tab cout << "Strength = " << strength<<endl;\par
\tab cout << "Attack = " << attack<<endl;\par
\tab cout << "Defense = " << defense<<endl;\par
\tab cout << "Level = "<< level<<endl;\par
\tab cout << "Maximum Damage = " << maxDamage<<endl;\par
\tab cout << "Minimum Damage = " << minDamage<<endl;\par
\};\par
\par
//ALL BASE CLASS^^^^ FROM HERE DOWN IS INHERITED*****************\par
\par
class Dragon : public Monster\par
\{\par
public:\par
\tab ~Dragon(void);\tab\par
\tab Dragon(int HP,\tab int Strength, int Attack, int Defense, int Level , int MaxDamage, int MinDamage);\par
\tab void PrintStats();\par
\tab \par
\};\par
\par
//CONSTRUCTORS() *******************************************************\par
Dragon::Dragon(int HP,\tab int Strength, int Attack, int Defense, int Level , int MaxDamage, int MinDamage) : Monster(HP, Strength, Attack, Defense, Level , MaxDamage, MinDamage)\par
\{\tab\tab\par
\tab HP = 88;\par
\tab Strength = 88;\par
\tab Attack = 88;\par
\tab Defense = 88;\par
\tab Level = 88;\par
\tab MaxDamage = 22;\par
\tab MinDamage = 0;\par
\par
\};\par
\par
\par
\par
//DESTRUCTORS*********************************************************\par
\par
Dragon::~Dragon()\par
\{\par
\tab int HP = 0;\par
\tab int Strength = 0;\par
\tab int Attack = 0;\par
\tab int Defense = 0;\par
\tab int Level = 0;\par
\tab int MaxDamage = 0;\par
\tab int MinDamage = 0;\par
\tab\par
\};\par
}
And the .cpp file looks like this :
#include "MonStats.h"
#includeint main()
{
Dragon drag;
drag.PrintStats();
return 0;
}
Ive been trying to debug this damn thing for about 5 hours now, and im sick of it, is there something so obvious i should be slaped for asking whats wrong here?GIMPS

"is there something so obvious i should be slaped for asking whats wrong here"
-yes.
"c:\program files\microsoft visual studio\alchemyst.cpp(1) : fatal error C1083: Cannot open include file: 'MonStats.h': No such file or directory"
That means that MonStats.h cannot be found. Make sure that you're giving the header file the same name (and that you have a header file...you didn't list it on there), and that it's in the correct directory.You declare functions in the header file, and define them in the .cpp file. So MonStats.h would look something like this:
#ifndef H_MONSTATS_H
#define H_MONSTATS_H//declare class, funtions, and variables here
#endif
While the MonStats.cpp file would look like this:
#include "MonStats.h"
//DEFINE functions and variables hereNote that it doesn't HAVE to have the same name as the header file (MonStats), but it's good practice to do so.
AKhalifman@hotmail.com

BTW, .cpp files are, by standard, plain text files. It looks like you copied the plain text of an .rtf document, which cannot be compiled by [us] simply copying/pasting.
Please make sure that you're using plain-text format for your code, especially when you post it here.
AKhalifman@hotmail.com

yea, i wrote the header file on my laptop and then compiled it with the .cpp file and it wouldnt work, so i transfered it to my computer but doing so added all that weird text to it.
thanks for answering that question raja :-D im gonna get to work on it right away.GIMPS

Well blue,
It seems i need to be slapped again.after putting
#ifndef H_MONSTATS_H
#define H_MONSTATS_H at the top of my header file and#endif
at the very end
then putting#include "MonStats.h"
at the top of my .cpp file, it still wouldnt not compile for the same reasons.
Then i decided to re read some stuff on classes and defining functions.
I then deleted both destructors since the only problem im having is with the constructors, then declared the HP, Strength, Attack, Deffense, Level, MaxDamage, and MinDamage as global variables;
Then i went through the code and deleted each parameter list and it worked fine once through, but it only printed out 0's for each stat.
I had no idea why my damn dragon constructor just will not work.
So ive been experimenting with the parameters and where i tell it to make HP and the other capital variables = numbers.
And it started to give me an error saying something about this call __ Dragon::Dragon(void) or something like that.So yea, it seems im just digging myself deeper and deeper into confusion ... I think i bit just a little more off than i can chew here....
*chokes*
GIMPS

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |