Compiler doing weird things.

Apr 16, 2013 at 5:03pm
In the main file or "application" file I have
#include <iostream>
#include "general.h"

using namespace std;

int main()
{
General bif;
cout << bif.lvlUp();
}

In the header file, "general.h" I have:
#include <iostream>
class General
{
public:
int lvlUp();
};
and in the implementation file I have:

// Elvaan.cpp
// implementation file

#include <iostream>
#include "general.h"
using namespace std;
int General::lvlUp()
{
int blah;
blah += blah * 5;



return blah;
}

I'd like to know why it gives me "320982646" or some other nonsense like "nan" or a really long number. My goal is to organize my code as well as it can be, I'm new to c++ and new to using multiple files, I'm trying to make a test-based rpg and have the variables in one files (initiated) and be able to use them in another, the idea is to have about 4 different jobs like "warrior, paladin, etc" and 4 different stats, I'd like to be able to organize all of these things into different files but so far I've had no such luck.



Apr 16, 2013 at 5:06pm
this creates an integer but doesn't initialize it (its contents are some garbage:
int blah;

this increments that garbage by five times that same garbage
blah += blah * 5;

this returns it to the caller, which is your main()
return blah;
Last edited on Apr 16, 2013 at 5:07pm
Topic archived. No new replies allowed.