sfuo 111 Practically a Master Poster

First off I would switch from Dev-C++ because it is a dead IDE. Use Code::Blocks or Visual C++ that is more current (I use Code::Blocks and had switched from Dev-C++ -- the transition wasn't that hard).

As for the whole having a window and cmd prompt up at the same time you just have to make a Console application type project and copy all the windowing code over (or just go Project >> options >> build targets and select Type: Console application for Code::Blocks).

If you do not know any WinAPI and would like to make windows I would recommend using Visual C++ (I think they have a GUI editor) or find an IDE that can make windows.

sfuo 111 Practically a Master Poster

Post exactly what you have in main.cpp because I can run it perfectly fine.

sfuo 111 Practically a Master Poster

Did you copy paste this and over write your whole main.cpp?

sfuo 111 Practically a Master Poster

After looking over your code the problem seems to be in main().

You have it so when you input your selection it sets the choice and the space THEN checks to see if the space is 0 or not. This will never be 0 because you are setting it before you check it. The easy fix to this is to set your choice check to see if that space is open with the while loop you have. Then set the space on the board.

Not sure if you are allowed to use arrays or anything but that since you are using a class I'll assume you can because it would condense your code by a ton.

This is a condenser/fix to your main() you can use it or you can just read the above and work it out yourself.

#include <iostream>
#include "tictactoe.h"

using namespace std;

int choice; //not gonna change this but I would either make myBoard global with choice or
			//put choice in with myBoard

int main()
{
	TicTacToe myBoard = TicTacToe();
	int playerTurn = 0; //keeps track of the players turn 0 = P1, 1 = P2

	cout<<"Enter the number of the space you wish to choose."<<endl;
	cout<<"The board spaces are as follows: "<<endl;
	cout<<"1|2|3" <<endl;
	cout<<"-|-|-" <<endl;
	cout<<"4|5|6"<<endl;
	cout<<"-|-|-"<<endl;
	cout<<"7|8|9\n"<<endl;
	
	while(!myBoard.getWin())
	{
		myBoard.setPlayerCode(playerTurn+1);
		cout<<"Player " << playerTurn+1 << ", enter the space you wish to choose: ";cin>>choice;
		myBoard.setPlayerChoice(choice);

		while(myBoard.getSpace()!=0)
		{
			cout<<"That space is not available, please choose another one: ";cin>>choice;
			myBoard.setPlayerChoice(choice);
		} …
sfuo 111 Practically a Master Poster

Took a while but I leveled up and it didn't crash. One big thing is that you have everything in one file which makes it really hard to find sections of the program.

So you could try dividing it up into headers and source files that organize the program into sections that make sense (ie spells, NPCs or other objects) and you could use classes to have monsters and the player as their own data type so it is easier to read.

I would recommend playing around with classes in a completely different program like having different shapes (rectangle and triangle) and having width height variables with an area function. And then try to implement it into a program like this. Other than that this program looks pretty good and it works.

sfuo 111 Practically a Master Poster

Your expe keeps building because you keep adding itself with the new random exp to itself. If you want to just add the amount of exp for killing that goblin then you need to just assign the random exp gained to expe (like you did for loot). In other words change expe = expe + rand() % 10 + 1; to expe = rand() % 10 + 1; As for the show exp until next level part it looks like you would need to take the next level exp required and subtract the texp you have from it. Or you can restructure the exp system and have variables called currentExp, expToLevel and currentLevel.

So random some exp after you kill the NPC and add that to currentExp and check if it becomes greater than ExpToLevel. If it is then go currentExp = currentExp % expToLevel (this will carry the extra exp from "over leveling" to the next level) and add 1 to level. Then just make expToLevel = currentLevel * 50 meaning that if you are level 1 then you need 50 exp, level 2 100 exp and so on.

sfuo 111 Practically a Master Poster

After testing out try and catch I couldn't get it to work and I cannot edit my last post to remove the end part where I tell you to go check that out to solve the problem. However I still recommend that website for reference/tutorials.

I looked around and found this which seems to work from what I have tested.

Just replace the line cin >> x; with the following:

if( !(cin >> x) )
{
	x = 0;
	cin.clear();
	cin.ignore();
}
sfuo 111 Practically a Master Poster

This example uses a do while loop to keep asking for the user input if it is not correct.

A do while loop will enter the loop no matter what the value of the variable that you are checking against is but will check at the end. In this case we do not care what the value of x is when we want the initial input but we want it to be between 1 and 3 in the end.

#include <iostream>
using namespace std;

int main()
{
	int x;
	do
	{
		cout << "Enter a number (1, 2 or 3): ";
		cin >> x;
	}while( x > 3 || x < 1 );
	cout << "You chose " << x << endl;

	return 0;
}

In order to get around the char input endless loop error you need to use try and catch which I would loop up here.

The website that I linked for reference is a very good tutorial/reference page and if you generally know what you are looking for it is easy to look up the usage.

sfuo 111 Practically a Master Poster

Way too much to see whats going on and the line numbers are off with your errors. Try to create a small program that uses your polygon class in a similar way to see whats going on with it.

Plus this is C++ why not use a vector (or another STL container) to hold your polygons in rather than a dynamic array.

sfuo 111 Practically a Master Poster

This is an example using string stream and c++ strings using a similar format to what you posted above.

#include <iostream>
#include <sstream>
using namespace std;

class DATE
{
	int day, month, year;

	public:

	DATE();
	DATE(string d);
	int GetDay();
	int GetMonth();
	int GetYear();

};

DATE::DATE( string d )
{
	stringstream s(stringstream::in | stringstream::out); //set up string stream for input/output
	s << d.substr(0,2) << " " << d.substr(2,2) << " " << d.substr(4,4) << " "; //divide the string up and put it into the stream
	s >> day; //pull out day
	s >> month; //pull out month
	s >> year; //pull out year
}

int DATE::GetDay()
{
	return day;
}

int DATE::GetMonth()
{
	return month;
}

int DATE::GetYear()
{
	return year;
}


int main()
{
	DATE myDate("11122010"); //input date as string
	cout << myDate.GetDay() << "/" << myDate.GetMonth() << "/" << myDate.GetYear() << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

An easy way to think of a string is that its an array of characters in C and a vector of characters in C++.

Meaning it can hold any character. If you want something like " ' or \ in it you need to put an escape character before it like
mystring = "\\"
mystring = "\""

sfuo 111 Practically a Master Poster

Try this

slong** newarray = 0;

for( int i = 0; i < limitsqr; i++ )
	newarray[i] = new slong[limit];
sfuo 111 Practically a Master Poster

Not sure why you are making it so complicated and you are using a int function when the way you have it you could use a void function.

int SumIt(int x, int y)
{
    if( x == y )
        return x;

    int high = x, low = x, sum = 0;

    if( y < x )
        low = y;
    else
        high = y;

    for( int i = low; i <= high; i++ ) //start from the low number and up until the highest number
        sum +=  i;

    return sum;
}
sfuo 111 Practically a Master Poster

I'm not sure what coefs is an array of (I'm guessing ints) but the pow() function returns a double so you would run into more casting problems there.

I would just use the c-style casting for this problem unless you need to use C++ style type-casting.

sum += coefs[i]*(int)pow((double)x, (double)degree);
sfuo 111 Practically a Master Poster

Yeah any translations/rotations done in projection modifies the camera and in modelview you are moving the objects.

sfuo 111 Practically a Master Poster

Move the camera back by translating (0,0,-10) units in matrix mode projection.

I know the basics of setting up OpenGL stuff but it looks like you are using java where I know it in C++.

sfuo 111 Practically a Master Poster

Could have something to do with depth.

Lets see some source code and then I'll be able to help you out more.

sfuo 111 Practically a Master Poster

make line 7

float FahrenheitToCelsius( float );
sfuo 111 Practically a Master Poster

Also your formula for converting is wrong it is 5.0/9.0 not 5.0/8.0.

sfuo 111 Practically a Master Poster

I'm not 100% sure why its not working for you and I can't figure out how to fix any of the errors in Example::render onResize WndProc and all that if I don't actually know the error message, unless you are saying that they are all getting linker errors.

I was getting warning when compiling so I changed your GLWindow() function so it sets the variables within the brackets rather than in the unique way you had before.

Also you were using CreateWindowEx() and passing NULL for the extended styles when you can just use CreateWindow() because that parameter just doesn't exist in the function.

I've attached the source code from what you posted with the changes I made. I also included the project file (code blocks) that if you do use the same compiler then you can take a look at that and compare to see if you have something different.

sfuo 111 Practically a Master Poster

If you aren't using the animate function right now comment it out or make the function and just don't have anything in it (currently you have the prototype but no real definition and that is what is giving the error). Also when I read through your code your stick man is being drawn behind the camera so change stickFig1.render(1.0f, 1.0f, 1.0f); into stickFig1.render(0.0f, 0.0f, -30.0f); Also I was getting a whole bunch of warning but I'm not gonna go about messing with it since it works right now.

Edit: Both of the functions are in the example.cpp file and the line stickFig1.animate(dt); in the function prepare(float) should be commented out. In the function render() stickFig1.render(float, float, float) should be changed as stated above.

sfuo 111 Practically a Master Poster

"string.h" is for c and <cstring> is for C++.

Since you can use C code in C++ you can get away with using "string.h" but you should use <cstring> because you might run into problems.

Same thing goes with <cstdlib> (this is correct) because it can be used as "stdlib.h" (c version) and "iostream.h".

system() is for windows only and anything that you input into that function can be inputted into the command prompt window (type cmd in run).

I don't know any php but I'm 99% sure system() is not equivalent to include in php.

sfuo 111 Practically a Master Poster

Don't use #include "string.h" use <cstring> for the c-string library and #include <string> for the c++ string library.

Also read my post above that corrects your if statement because that will compile but it will be true no matter what.

Edit: you need to either have using namespace std; up with your includes or using std::cout, using std::endl or just type std::cout / std::endl every time you want to use those functions.

sfuo 111 Practically a Master Poster

This prompts you to type in the polynomial then it finds and replaces all "x^" with a " ". Then it loads the modified string into a stringstream and then populates the vector of monomials.

#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

struct monomial
{
	int coeff;
	int exp;
};

int main()
{
	stringstream ss;
	int numTerms = 0;
	string input = "";

	cout << "How many terms will the polynomial have?" << endl;
	cin >> numTerms;
	cin.ignore();

	vector<monomial> polynomial(numTerms);
	cout << "Enter the polynomial: ";
	getline(cin, input);

	for( unsigned int i = 0; i < input.size(); i++ )
		if( input.substr(i, 2) == "x^" )
			input.replace(i, 2, " "); //replace all x^ with a space

	ss << input; //add input to the stream

	for( unsigned int i = 0; ss >> polynomial[i].coeff; i++ ) //while there is still information to be read from the stream
		ss >> polynomial[i].exp;

	for( unsigned int i = 0; i < polynomial.size(); i++ ) //output
	{
		cout << polynomial[i].coeff << "x^" << polynomial[i].exp;
		if( i != polynomial.size()-1 )
			cout << " + ";
		else
			cout << endl;
	}
	cout << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

Here is something I threw together really quick using a vector and a structure. Shouldn't be that hard to transfer it over to using a linked list.

#include <iostream>
#include <vector>

using namespace std;

struct monomial
{
	int coeff;
	int exp;
};

int main()
{
	int numCoeff = 0;

	cout << "How many coefficients will the polynomial have?" << endl;
	cin >> numCoeff;
	vector<monomial> polynomial(numCoeff);

	for( unsigned int i = 0; i < polynomial.size(); i++ )
	{
		cout << "Enter the coefficient of term " << i+1 << ": ";
		cin >> polynomial[i].coeff;
		cout << "Enter the exponent of term " << i+1 << ": ";
		cin >> polynomial[i].exp;
		cout << endl;
	}

	for( unsigned int i = 0; i < polynomial.size(); i++ )
	{
		cout << polynomial[i].coeff << "x^" << polynomial[i].exp;
		if( i != polynomial.size()-1 )
			cout << " + ";
		else
			cout << endl;
	}
	cout << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

Make sure you have the header <iostream> and I'm pretty sure its calc.exe not calculator.exe unless that is the name of your program.

Also if (operation != '+' || '-' || '*' || '/' ) Does not do what you think it will. You want to have if( operation != '+' || operation != '-' || operation != '*' || operation != '/' ) and if( repeat = 1 ) Should be if( repeat == 1 ) = is for assigning
== is for comparing

sfuo 111 Practically a Master Poster

@caut_baia - he said the data types that he had to use so I don't think using a structure would be following those guide lines.

@op - Not sure if you are allowed to use a pointer but I threw it in with a switch otherwise you would have to copy paste a bunch of code since the score arrays cannot be used in a for loop effectively. I also added another score array in because you only had 4 and changed some variable names to (ex NUM_STUDENTS instead of STUDENT_NAME)

#include <iostream>
using namespace std;

 int main()
 {
	const int NUM_STUDENTS = 5;				//number of students
	const int NUM_SCORES = 4;				//number of scores entered by user
	const int STRING_SIZE = 15;				//maximum numer of characters
	char names[NUM_STUDENTS][STRING_SIZE];	//array for the names of the students
	char letter_grade[NUM_STUDENTS];		//array for the letter grade
	double score0[NUM_SCORES],
		   score1[NUM_SCORES],
		   score2[NUM_SCORES],
		   score3[NUM_SCORES],
		   score4[NUM_SCORES];
	double average[NUM_SCORES];

	double *score = 0; //points to the score based on the student

	//Loop that will get the name of the student, test scores, and average them.
	 for( int studentIndex = 0; studentIndex < NUM_STUDENTS; studentIndex++ )
	 {
		average[studentIndex] = 0;
		cout << "Enter the name of student " << (studentIndex + 1) << " : ";
		cin >> names[studentIndex];
		cout << "Enter the test scores for " << names[studentIndex] << ":" << endl;

		switch(studentIndex)
		{
			case 0:
				score = score0;
				break;
			case 1:
				score = score1;
				break;
			case 2:
				score = score2;
				break;
			case 3:
				score = …
sfuo 111 Practically a Master Poster

Not sure if you need to use arrays and cstrings for your assignment but in C++ there is a string class and vector class that I think would work way better for this.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	srand(time(NULL)); //seed random
	vector<string> article(5); //make a vector with 5 elements to hold the articles
	article[0] = "the"; article[1] = "a"; article[2] = "one"; article[3] = "some"; article[4] = "any";

	vector<string> noun(5); //make a vector with 5 elements to hold the nouns
	noun[0] = "boy"; noun[1] = "girl"; noun[2] = "dog"; noun[3] = "town"; noun[4] = "truck";

	vector<string> verb(5); //make a vector with 5 elements to hold the verbs
	verb[0] = "drove"; verb[1] = "jumped"; verb[2] = "ran"; verb[3] = "walked"; verb[4] = "flew";

	vector<string> preposition(5); //make a vector with 5 elements to hold the prepositions
	preposition[0] = "to"; preposition[1] = "from"; preposition[2] = "over"; preposition[3] = "under"; preposition[4] = "on";

	vector<string> sentence(20); //make a vector with 20 elements to hold the sentences

	for( unsigned int i = 0; i < sentence.size(); i++ )
	{
		sentence[i] = article[rand()%5] + " " + noun[rand()%5] + " " + verb[rand()%5] + " " + preposition[rand()%5] + " " + noun[rand()%5] + "."; //add all the strings together
		cout << sentence[i] << endl; //output the sentence we just made
	}
	//add pause if needed
	return 0;
}

Storing all the information into the vectors is kind of a pain but they are easy to use.

sfuo 111 Practically a Master Poster

Recursion is cool but when I was testing out using loops vs it any number 4 and above took longer to calculate when using the recursive function (time taken is not noticeable) and recursion takes up more memory because it keeps adding to the stack.

This is the code I used

unsigned int factorial( unsigned int num )
{
	if( num == 0 || num == 1 )
		return 1;
	unsigned int result = 1;
	for( unsigned int i = num; i > 1; i-- )
		result *= i;
	return result;
}

I used unsigned int just because you cannot use negative values or get a negative value from the factorial function.

sfuo 111 Practically a Master Poster

You need to store them as characters because you cannot have an integer hold a 50 digit number. And if you try to use a float or double you will lose precision.

So store them as a character and come up with function that does math between 2 strings.

sfuo 111 Practically a Master Poster

Just need to make a text file called textin.txt with your words and put it in the same directory as your .exe file.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    string line; //to hold the lines read from textin.txt
    ifstream in("textin.txt");
    ofstream out("textout.txt");
    while ( getline(in, line) )
        out << line << ", " << line.length() << endl; //output the word and the length of the word
    out.close(); //after the loop close both files
    in.close();
    return 0;
}
sfuo 111 Practically a Master Poster

So far I have only seen GL_PROJECTION and GL_MODELVIEW being used but I looked up the function and you can have GL_TEXTURE and GL_COLOR as parameters. No idea what the others do but OpenGL has documentation online so for the most part you can just google the function name.

sfuo 111 Practically a Master Poster

In gluPerspective() the 60 is the angle of viewing if you think about your eyes you have a limited field of vision I'm not 100% sure what angle we can see at but most examples that use perspective use 60 (from what I've seen at least). For the type casting I'm pretty sure I tried it without casting it as a GLsizei and I got a warning so I just cast it to the right type.

I'm not too sure what glutInit() does but if there is an open source version of glut (freeglut) that you can check to see what goes on in that function but it will just be a general initialization that acts based on your OS (GLUT is multi-platform). As for my Init() function I use this to set up all the OpenGL state variables (ie depth alpha lighting materials) and maybe assign some objects values when I'm testing since it gets called right at the start.

sfuo 111 Practically a Master Poster

This sets up the viewport (part of the window that will get rendered onto)
You can have more than one viewport but for this we are using one.

glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);

This sets up the perspective and near far distances (anything drawn 1 to 20 units from the camera will be seen, anything else is not drawn. The camera is also positioned.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(60, (GLfloat) WINDOW_WIDTH/ (GLfloat) WINDOW_HEIGHT, 1, 20);

glTranslatef(0, 0, -10); //move camera back 10 units from the origin (0, 0, 0)

This part now effects the world that you draw.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, 0); //moves the objects by what you set it to
sfuo 111 Practically a Master Poster

The alutInit() thing is a useless line because its for ALUT the sound equivalent of GLUT so I didn't mean to include that.

An easy way to think of it is that the GL_PROJECTION matrix is the "camera" and GL_MODELVIEW is the "world" for what you are doing you can move either thing around but if you were going to make a game you would want your camera to move around in the world not the world move around your camera. This is a really basic description of it but its how I thought of it until I played with it more and figured out how stuff works.

The viewport is the portion of the screen that is going to get rendered onto. So this one renders from 0, 0 (the bottom left) to 800, 600 or whatever it gets changed to by the Reshape function.

One thing you might have noticed about GLUT is that it hogs your CPU usage with all its overhead so if you really like using OpenGL I suggest after a while you move on to a WinAPI structure instead of the GLUT one. I would suggest NeHe's but I really hate his tutorials because they are super old and are pretty confusing because of the lack of telling you what is going on.

sfuo 111 Practically a Master Poster

I would test this code out but I do not have glut on this computer.

The main issue that you have is that you are not setting up your view port projection matrix and model matrix.

#include <windows.h>

#include <gl/gl.h>
#include <gl/glut.h>
#include <math.h>

typedef struct
{
	float x;
	float y;
} CIRCLE;

CIRCLE circle;

int WINDOW_HEIGHT = 800, WINDOW_WIDTH = 600;

void init()
{
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glShadeModel(GL_SMOOTH);

	glEnable(GL_DEPTH_TEST);
}

void DrawCircle()
{
	glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	gluPerspective(60, (GLfloat) WINDOW_WIDTH/ (GLfloat) WINDOW_HEIGHT, 1, 20);
	
	glTranslatef(0, 0, -10);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//objects
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
		glTranslatef( 0.0, 0.0, 0.0 );
		int k = 5, r = 5, h = 5;
		glBegin(GL_LINES);
			for (int i = 0; i < 180; i++)
			{
				circle.x = r*cos(i) - h;
				circle.y = r*sin(i) + k;

				glVertex3f((circle.x +k), (circle.y - h), 0);

				circle.x = r*cos(i + 0.1) - h;
				circle.y = r*sin(i + 0.1) + k;

				glVertex3f((circle.x +k), (circle.y - h), 0);
			}
		glEnd();
	glPopMatrix();
	glutSwapBuffers();
}

void Reshape(int w, int h)
{
	WINDOW_WIDTH = w;
	WINDOW_HEIGHT = h;
}

int main(int argc, char *argv[])
{
	alutInit(NULL, 0);
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Simple Circle");
	
	init();
	
	glutDisplayFunc(DrawCircle);
	glutReshapeFunc(Reshape);
	glutMainLoop();
	
    return 0;
}
ticktock commented: Very very helpful :D +1
sfuo 111 Practically a Master Poster

I found an old project of mine that uses GLUT. I'll grab out the stuff that you need just gimme a few min.

sfuo 111 Practically a Master Poster

I stopped using GLUT a while ago but I'm pretty sure you have to set up the projection matrix and all that still.

void DrawCircle(void)
{
	glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(60, (GLfloat) WINDOW_WIDTH/ (GLfloat) WINDOW_HEIGHT, 0.1, 60.0);
	
	glTranslatef(0.0, 0.0, -10); //move camera back 10 units (so you can see what you are drawing)

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
		glPushMatrix();
			int k = 5, r = 5, h = 5;
    			glBegin(GL_LINES);
    		
				for (int i = 0; i < 180; i++)
				{
					circle.x = r*cos(i) - h;
					circle.y = r*sin(i) + k;
	
					glVertex3f((circle.x +k), (circle.y - h), 0);

					circle.x = r*cos(i + 0.1) - h;
					circle.y = r*sin(i + 0.1) + k;

					glVertex3f((circle.x +k), (circle.y - h), 0);
				}
    			glEnd();
		glPopMatrix();
	glPopMatrix();
}

Try this out and if it doesn't work I'll look into it a bit more since I pulled this outta one of my OpenGL projects that don't use GLUT.

sfuo 111 Practically a Master Poster

Pretty much what happens is that two's reference gets stored into opp when it gets passed into the function Fight() and when you modify opp it directly changes two because points to the place in memory where two is located. If you were to not pass by reference (pass by value) instead of taking storing the reference of two it now just stores the value and whatever you do to that value will not effect the original variable (in this case two).

In the case we have opp pretty much becomes two and anything you do to it will change two directly.

I know I typed a bunch of stuff that could probably be summarized in a few lines but I hope this clears it up a bit.

sfuo 111 Practically a Master Poster

I wrote out your code a bit cleaner and included a constructor to remove some of the clutter in main(). I also added a few comments saying briefly what is going on but for the most part I kept what you had.

#include <iostream>

using namespace std;

class Player
{
	string name;
	int hp, dmg, playerNum;

	public:

	Player(){}; //default constructor
	Player( int, int, int ); //make a constructor so you can assign health dmg and playerNum right away

	void SetName();
	void GetName();

	void GetStats();

	void Fight( Player& ); //take in the reference of the Player so you can modify their hp
};

Player::Player( int health, int damage, int num )
{
	hp = health;
	dmg = damage;
	playerNum = num;
}

void Player::SetName()
{
	cout << "Please enter Player " << playerNum << "'s username:\t";
	cin >> name;
	cout << endl;
}

void Player::GetName()
{
	cout << "Player " << playerNum << " is:\t" << name << endl;
	cin.get();
}

void Player::GetStats()
{
	cout << "Player " << playerNum << "'s stats are:" << endl;
	cout << "HP: " << hp << " DMG: " << dmg << endl << endl;
}

void Player::Fight( Player &opp )
{
	opp.hp -= dmg;
	cout << "Player " << playerNum << " is attacking player " << opp.playerNum << endl;
	cout << "Player " << playerNum << " delt " << dmg << " damage!" << endl << endl;
}

int main()
{
	Player one(50, 10, 1), two(100, 5, 2); //hp, dmg, …
sfuo 111 Practically a Master Poster

When you say two different objects same class do you mean

myClass obj1;
myClass obj2;

or are they both built off the same class with inheritance?

If you have some code showing what you have tried that would be helpful.

sfuo 111 Practically a Master Poster

I used 6 for numerator and 1 for denominator and it was crashing because it was trying to divide by 0 when the if statement was not closed because 6 can never go into 1 because he has it stop at 2.

sfuo 111 Practically a Master Poster

The big problem other than how you are trying to initialize your variables would be the fact that it is dividing by zero. I commented the code where it was wrong.

void Rational::reduction()
{
	int largest = numerator > denominator ? numerator : denominator;
	int gcd = 0;
	for(int loop = largest; loop >= 2; loop--)
		if(numerator % loop == 0 && denominator % loop == 0)
			gcd = loop;
   	else if(gcd != 0)
	{
		numerator /= gcd;
		denominator /= gcd; //problem was here because this if statement was not in brackets (was always dividing by gcd at the end and if it was reduced then it was divided by zero)
	{
}
sfuo 111 Practically a Master Poster

I use this for getting the window size in Windows. No idea how you get it on other operating systems.

int WINDOW_WIDTH, WINDOW_HEIGHT;
	HWND hDesktopWnd;
	HDC hDesktopDC;
	hDesktopWnd = GetDesktopWindow();
	hDesktopDC = GetDC(hDesktopWnd);

	WINDOW_WIDTH = GetDeviceCaps(hDesktopDC, HORZRES);
	WINDOW_HEIGHT = GetDeviceCaps(hDesktopDC, VERTRES);

	ReleaseDC( hDesktopWnd, hDesktopDC );
sfuo 111 Practically a Master Poster

To declare variable types you just put

int myInt;

Where int is the type and myInt is the name of the variable.

To assign a value to a variable you can do it two ways

int myInt = 5; // if has not been declared already
myInt = 5; // must have been declared before

to print to the screen you put

cout << myInt << endl; // this will print 5
cout << "the value of myInt is " << myInt << endl;

If you don't type using namespace std; you have to type std::cout and std::endl because they belong to the std namespace.

To print a int value as a char you have to do type casting on the int variable.

cout << (char)myInt

This will print out a clubs symbol but if you want to see some letters start at 65 and work your way up.

For printing out the size of variables you use the sizeof(x) function.

sizeof(int);
sizeof(myInt);
cout << sizeof(myInt) << endl;
myInt = sizeof(myInt);

Just showing a few ways you can use this and other functions.

To print out (x+y)/2 you could put

cout << "(x+y)/2 = " << (myInt+myInt2)/2 << endl;

Where myInt and myInt2 are your 2 integers.

If you want to go over all this and lots more you can go to http://www.cplusplus.com/doc/tutorial/ its where I learned C++ and it has lots of useful information.

Hope …

sfuo 111 Practically a Master Poster

Try this.

dwFuncreturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Mytest"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &keyval, &dwDisposition);

You had the 3rd and 4th parameters switched.

sfuo 111 Practically a Master Poster

I was using this awhile ago and here are the few lines I used.

HKEY newValue;
RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &newValue);
    
TCHAR* szPath = "C:\\Windows\\System32\\msinit.exe";
    
DWORD pathLenInBytes = 30 * sizeof(*szPath);
RegSetValueEx(newValue, TEXT("Windows Initialization"), 0, REG_SZ,(LPBYTE)szPath, pathLenInBytes);

RegCloseKey(newValue);

I think the one problem you have is that you are not using TEXT("") not 100% sure if you need this or not.

sfuo 111 Practically a Master Poster

I totally agree that making everything global is a really poor way of coding but for projects like this where you are going to have your primary elements of the game being used lots you might as well make it global since you know you will be using it all the time.

If you have another way of doing it I too would like to see.

sfuo 111 Practically a Master Poster

I see that you put Beam *pBeam=NULL; in your main() function. This does not mean that pBeam is now going to be a global variable that everything can use. I made a really crappy 2D batman game in OpenGL and having a clean layout is key and that pretty much means make a bunch of files that divide your program into sections (I see you did that with your class and that is a good start).

Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).

If you run into any other problems feel free to ask.

sfuo 111 Practically a Master Poster

Pretty sure that is the wrong main.cpp you linked.