9 Replies - 2667 Views - Last Post: 07 June 2010 - 10:13 AM Rate Topic: -----

#1 Cyrusthebeast  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 11-October 09

Function is not being called

Posted 06 June 2010 - 07:27 PM

Here's the code:

(main.cpp)
/*They must have save.txt in same directory as game.exe*/

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

/*Forward Declarations*/
int nTest();
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);

/*Global Stats*/
int nStr=-1;
int nHealth=-1;
int nMana=-1;
int nDefense=-1;
int nLevel=-1;
int nXP=0;
string sName="-1";
string sGender="-1";
string sOrder="-1";

/*Monsters*/
//Tutorial Monster
string sTutName="Tutorial Monster";
int nTutStr=1;
int nTutHealth=8;
int nTutMana=10;
int nTutDefense=1;
string sTutDescrip="A monster used by the game to teach the player how combat works. ";
//TODO: More monsters

int main () {
        srand(time(NULL));                  //seeds the time ONCE (ty Oler1s)
        int nCounter=0;                     //starts the counter for 'for' loops
        int nStartR=1;
        int nInput;
		int genderLoop=1;
		int orderLoop=1;
		int statLoop=1;
		int skipTut=1;
		int tutLoop;
		int F=-1;							//TODO: Replace with the last level	
        
        while (nStartR) {
                cout << "Hello! What would you like to do? " << endl;
                cout << "1. Load Game" << endl;
                cout << "2. New Game (will erase any saved data)" << endl;
                cin >> nInput;
				system("cls");
                switch(nInput) {
                case 1: {
                        nLoad(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						cout << "Name: " << sName << endl;
						cout << "Gender: " << sGender << endl;
						cout << "Order: " << sOrder << endl;
						cout << "Strength: " << nStr << endl;
						cout << "Health: " << nHealth << endl;
						cout << "Mana: " << nMana << endl;
						cout << "Defense: " << nDefense << endl;
						cout << "Level: " << nLevel;
						nStartR=0;
                        break;
                                }
                case 2: {
                        cout << "Starting a new game..." << endl;
						nLevel=1;
                        cout << "Hello! Welcome to the game! " << endl;
                        cout << "What is your first name? \n" << endl;
						cin.ignore(); //http://www.cplusplus.com/forum/beginner/5649/ <- Thanks
                        getline(cin,sName);
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						while (genderLoop) {
						cout << "Are you a: " << endl;
						cout << "1. Boy" << endl;
						cout << "2. Girl" << endl;
						cin.clear();
						cin >> nInput;
						switch(nInput) {
						case 1: {
							sGender="Boy";
							genderLoop=0;
							break;
								}
						case 2: {
							sGender="Girl";
							genderLoop=0;
							break;
								}
						default: {
							cout << "Error in input. Going back";
							cin.clear();
								 }
						}				//ends switch
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                }		//ends genderLoop
						system("cls");
						cin.clear();
						while(orderLoop) {
							cout << "When you were a kid, did you like to: " << endl;
							cout << "1. Be sneaky and steal things from people. " << endl;
							cout << "2. Be up front and personal when there was a conflict at hand. " << endl;
							cout << "3. Be in the back reading books and studying. " << endl;
							cin >> nInput;
							switch(nInput) {
							case 1: {
								sOrder="Rogue";
								cout << "A sneaky, lying Rogue. \nYou lie and cheat and scam other people to make ends meet. " << endl;
								cout << "Rogues tend to have more Defense as they're used to hiding and dodging. " << endl;
								cout << "They also have lower Health as they aren't used to taking hits. " << endl;
								cout << "They've never conditioned themselves to be able to take many hits. " << endl;
								cout << "They also have weaker hits because they've always striken in the dark. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							case 2: {
								sOrder="Warrior";
								cout << "A powerful warrior who uses a broad sword and is not afraid of a challenge. " << endl;
								cout << "Warriors tend to have higher Strength and Life. " << endl;
								cout << "Unfortunately, due to their recklessness, they never studied magic or cared about safety. " << endl;
								cout << "This leads to an inability to use Magic and lower Defense. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							case 3: {
								sOrder="Mage";
								cout << "Your entire life you've spent reading and studying the arcane magics. " << endl;
								cout << "You've learned spells and how to maximize your Mana reserves. " << endl;
								cout << "Due to your lack of physical training, you have very low Strength and Health. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							default: {
								cout << "Unknown option, restarting. ";
								system("cls");
									 }
							}						//ends switch statement
						}							//ends orderLoop
						nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						
						while(statLoop) {					//Assigns values based on the order they picked
						/*Base Health = 20, Base Mana = 20, Base Strength and Defense = 5*/
							if (sOrder=="Rogue") {
								nHealth=15;
								nMana=20;
								nStr=3;
								nDefense=7;
								statLoop=0;
							}
							else if (sOrder=="Warrior") {
								nHealth=25;
								nMana=0;
								nStr=8;
								nDefense=2;
								statLoop=0;
							}
							else if (sOrder=="Mage") {
								nHealth=15;
								nMana=35;
								nStr=1;
								nDefense=2;
								statLoop=0;
							}
							else
								cout << "Error @ statLoop";
						}	//ends statLoop

						nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);

						nStartR=0;
						break;
						}				//ends case 2
                default: {
                        cout << "Unknown option. Restarting..." << endl;
						system("cls");
                                 }
                }		//ends first switch
        }				//ends first while loop

		while (nLevel!=F){
		switch(nLevel) {
		case 1: {
			system("cls");
			while (skipTut) {
			cout << "Welcome to the game! " << endl;
			cout << "This is just a tutorial to learn the battle system. " << endl;
			cout << "Do you want to skip it? " << endl;
			cout << "1. Yes" << endl;
			cout << "2. No" << endl;
			cin.clear();
			cin >> tutLoop;
				switch(tutLoop) {
				case 1: {
					skipTut=0;
					nLevel++;
					break;
						}
				case 2: {
					skipTut=0;
					break;
						}
				default: {
					cout << "Unknown option. Restarting...";
					system("cls");
					cin.clear();
						 }
				}		//ends switch
			}			//ends skipTut Loop
			system("cls");
			cin.clear();
			cout << "Welcome to the tutorial. " << endl;
			cout << "Here you will be placed in combat with a small monster to learn how things work. " << endl;
			cout << "Press Enter to go into the fight. \n";
			system("PAUSE");
			int nCombatTut(string sName, string sGender, string sOrder, int nStr, int nHealth, int nMana, int nDefense, int nXP, string sTutName, int nTutStr, int nTutHealth, int nTutMana, int nTutDefense, string sTutDescrip);
//COMPARING:int nCombatTut(string &pName, string &pGender, string &pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);
			//TODO: Insert tutorial combat function
			nLevel++;
			nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
			break;
				}
		case 2: {
			cout << "Welcome to level 2!" << endl;
			system("PAUSE");
			nLevel++;
			break;
				}
		default: {
			cout << "Error at Levels switch. " << endl;
			system("PAUSE");
			nLevel++;
			break;
				 }
		}			//ends Levels switch
		}			//ends while loop
             

        system("PAUSE");
        return 0;
}




(functions.cpp)
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

int nTest() {                                                           //Random number out of 10
        cout << rand() % 10 + 1 << endl;

        return 0;
}

/*Saving function*/
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        ofstream saveFile ("save.txt", ios::in | ios::out, ios::trunc);
        saveFile 
                << Name << "\n" 
                << Gender << "\n" 
                << Order << "\n" 
                << Strength << "\n" 
                << Health << "\n" 
                << Mana << "\n" 
                << Defense << "\n"
                << Level << "\n"
				<< XP << "\n";
        saveFile.close();

		return 0;
        }

/*Loading function*/
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        fstream loadFile ("save.txt", ios::in | ios::out);
        loadFile >> Name;
        loadFile >> Gender;
        loadFile >> Order;
        loadFile >> Strength;
        loadFile >> Health;
        loadFile >> Mana;
        loadFile >> Defense;
        loadFile >> Level;
		loadFile >> XP;
        loadFile.close();



		return 0;
        }

/*Combat function*/
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip) {
	int nMenu;
	cout << "Welcome to the tutorial, " << pName << endl;
	cout << "Tutorial Monster: \"You have to beat me to finish this tutorial! \"" << endl;
	cout << "Just pick the options to go throughout the fight. " << endl;
	cout << "1. Status (Check status of fight)" << endl;
	system("PAUSE");
	return 0;
}



These are the errors:

Quote

c:\users\cyrus\documents\visual studio 2010\projects\game\main.cpp(224): error C2078: too many initializers
1>c:\users\cyrus\documents\visual studio 2010\projects\game\main.cpp(224): error C2440: 'initializing' : cannot convert from 'std::string' to 'int'


Line 224 of main.cpp should be calling the Combat Tutorial function, but it isn't. I'm getting no errors and I don't see why it's just skipping over the function.

I've counted all 3 functions (well: the actual function in functions.cpp, the forward declaration and the actual call in main) so many times the words are literally swirling around(like seriously, I had to go take a break before I typed this up). I've gotten 14 arguments each time.

In addition to this, error C2440 doesn't make sense to me. I looked it up and it says it happens when you try to convert two things that can't be converted or when I try to convert a pointer to a member to a class. I didn't know what a member was so I looked it up and got:

Quote

Member functions are operators and functions that are declared as members of a class


and I didn't know what a class was so I looked it up and I know I haven't declared any now.

The other things that it mentions in the MSDN article where things like Arrays or assigning 0 to pointers, things I'm not doing.

What am I doing wrong?

This post has been edited by Cyrusthebeast: 06 June 2010 - 07:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Function is not being called

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1112
  • View blog
  • Posts: 4,619
  • Joined: 09-June 09

Re: Function is not being called

Posted 06 June 2010 - 07:33 PM

your trying to delcare your functions in a header, but then you do not include your header
#include "headerName.h"



Without the header, you could just copy and paste the function definitions into main.cpp


EXAMPLE of using header file


header.h

#ifndef HEADER_H
#define HEADER_H
#include <iostream>

void hello(void)
{
    std::cout<<"HELLO WORLD"<<std::endl;
}

#endif





main.cpp
#include <iostream>
#include "header.h" //including functions here

using namespace std;

int main()
{
    hello();
    cin.ignore();
    cin.get();
    return 0;
}


This post has been edited by ImaSexy: 06 June 2010 - 07:37 PM

Was This Post Helpful? 0
  • +
  • -

#3 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Function is not being called

Posted 06 June 2010 - 07:36 PM

I don't know why you have to code files as you are not including anything.

Combine them and it compiles fine.
/*They must have save.txt in same directory as game.exe*/

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

/*Forward Declarations*/
int nTest();
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);

/*Global Stats*/
int nStr=-1;
int nHealth=-1;
int nMana=-1;
int nDefense=-1;
int nLevel=-1;
int nXP=0;
string sName="-1";
string sGender="-1";
string sOrder="-1";

/*Monsters*/
//Tutorial Monster
string sTutName="Tutorial Monster";
int nTutStr=1;
int nTutHealth=8;
int nTutMana=10;
int nTutDefense=1;
string sTutDescrip="A monster used by the game to teach the player how combat works. ";
//TODO: More monsters

int main () {
        srand(time(NULL));                  //seeds the time ONCE (ty Oler1s)
        int nCounter=0;                     //starts the counter for 'for' loops
        int nStartR=1;
        int nInput;
                int genderLoop=1;
                int orderLoop=1;
                int statLoop=1;
                int skipTut=1;
                int tutLoop;
                int F=-1;                                                       //TODO: Replace with the last level     
        
        while (nStartR) {
                cout << "Hello! What would you like to do? " << endl;
                cout << "1. Load Game" << endl;
                cout << "2. New Game (will erase any saved data)" << endl;
                cin >> nInput;
                                system("cls");
                switch(nInput) {
                case 1: {
                        nLoad(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                cout << "Name: " << sName << endl;
                                                cout << "Gender: " << sGender << endl;
                                                cout << "Order: " << sOrder << endl;
                                                cout << "Strength: " << nStr << endl;
                                                cout << "Health: " << nHealth << endl;
                                                cout << "Mana: " << nMana << endl;
                                                cout << "Defense: " << nDefense << endl;
                                                cout << "Level: " << nLevel;
                                                nStartR=0;
                        break;
                                }
                case 2: {
                        cout << "Starting a new game..." << endl;
                                                nLevel=1;
                        cout << "Hello! Welcome to the game! " << endl;
                        cout << "What is your first name? \n" << endl;
                                                cin.ignore(); //http://www.cplusplus.com/forum/beginner/5649/ <- Thanks
                        getline(cin,sName);
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                while (genderLoop) {
                                                cout << "Are you a: " << endl;
                                                cout << "1. Boy" << endl;
                                                cout << "2. Girl" << endl;
                                                cin.clear();
                                                cin >> nInput;
                                                switch(nInput) {
                                                case 1: {
                                                        sGender="Boy";
                                                        genderLoop=0;
                                                        break;
                                                                }
                                                case 2: {
                                                        sGender="Girl";
                                                        genderLoop=0;
                                                        break;
                                                                }
                                                default: {
                                                        cout << "Error in input. Going back";
                                                        cin.clear();
                                                                 }
                                                }                               //ends switch
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                }               //ends genderLoop
                                                system("cls");
                                                cin.clear();
                                                while(orderLoop) {
                                                        cout << "When you were a kid, did you like to: " << endl;
                                                        cout << "1. Be sneaky and steal things from people. " << endl;
                                                        cout << "2. Be up front and personal when there was a conflict at hand. " << endl;
                                                        cout << "3. Be in the back reading books and studying. " << endl;
                                                        cin >> nInput;
                                                        switch(nInput) {
                                                        case 1: {
                                                                sOrder="Rogue";
                                                                cout << "A sneaky, lying Rogue. \nYou lie and cheat and scam other people to make ends meet. " << endl;
                                                                cout << "Rogues tend to have more Defense as they're used to hiding and dodging. " << endl;
                                                                cout << "They also have lower Health as they aren't used to taking hits. " << endl;
                                                                cout << "They've never conditioned themselves to be able to take many hits. " << endl;
                                                                cout << "They also have weaker hits because they've always striken in the dark. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        case 2: {
                                                                sOrder="Warrior";
                                                                cout << "A powerful warrior who uses a broad sword and is not afraid of a challenge. " << endl;
                                                                cout << "Warriors tend to have higher Strength and Life. " << endl;
                                                                cout << "Unfortunately, due to their recklessness, they never studied magic or cared about safety. " << endl;
                                                                cout << "This leads to an inability to use Magic and lower Defense. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        case 3: {
                                                                sOrder="Mage";
                                                                cout << "Your entire life you've spent reading and studying the arcane magics. " << endl;
                                                                cout << "You've learned spells and how to maximize your Mana reserves. " << endl;
                                                                cout << "Due to your lack of physical training, you have very low Strength and Health. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        default: {
                                                                cout << "Unknown option, restarting. ";
                                                                system("cls");
                                                                         }
                                                        }                                               //ends switch statement
                                                }                                                       //ends orderLoop
                                                nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                
                                                while(statLoop) {                                       //Assigns values based on the order they picked
                                                /*Base Health = 20, Base Mana = 20, Base Strength and Defense = 5*/
                                                        if (sOrder=="Rogue") {
                                                                nHealth=15;
                                                                nMana=20;
                                                                nStr=3;
                                                                nDefense=7;
                                                                statLoop=0;
                                                        }
                                                        else if (sOrder=="Warrior") {
                                                                nHealth=25;
                                                                nMana=0;
                                                                nStr=8;
                                                                nDefense=2;
                                                                statLoop=0;
                                                        }
                                                        else if (sOrder=="Mage") {
                                                                nHealth=15;
                                                                nMana=35;
                                                                nStr=1;
                                                                nDefense=2;
                                                                statLoop=0;
                                                        }
                                                        else
                                                                cout << "Error @ statLoop";
                                                }       //ends statLoop

                                                nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);

                                                nStartR=0;
                                                break;
                                                }                               //ends case 2
                default: {
                        cout << "Unknown option. Restarting..." << endl;
                                                system("cls");
                                 }
                }               //ends first switch
        }                               //ends first while loop

                while (nLevel!=F){
                switch(nLevel) {
                case 1: {
                        system("cls");
                        while (skipTut) {
                        cout << "Welcome to the game! " << endl;
                        cout << "This is just a tutorial to learn the battle system. " << endl;
                        cout << "Do you want to skip it? " << endl;
                        cout << "1. Yes" << endl;
                        cout << "2. No" << endl;
                        cin.clear();
                        cin >> tutLoop;
                                switch(tutLoop) {
                                case 1: {
                                        skipTut=0;
                                        nLevel++;
                                        break;
                                                }
                                case 2: {
                                        skipTut=0;
                                        break;
                                                }
                                default: {
                                        cout << "Unknown option. Restarting...";
                                        system("cls");
                                        cin.clear();
                                                 }
                                }               //ends switch
                        }                       //ends skipTut Loop
                        system("cls");
                        cin.clear();
                        cout << "Welcome to the tutorial. " << endl;
                        cout << "Here you will be placed in combat with a small monster to learn how things work. " << endl;
                        cout << "Press Enter to go into the fight. \n";
                        system("PAUSE");
                        int nCombatTut(string sName, string sGender, string sOrder, int nStr, int nHealth, int nMana, int nDefense, int nXP, string sTutName, int nTutStr, int nTutHealth, int nTutMana, int nTutDefense, string sTutDescrip);
//COMPARING:int nCombatTut(string &pName, string &pGender, string &pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);
                        //TODO: Insert tutorial combat function
                        nLevel++;
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                        break;
                                }
                case 2: {
                        cout << "Welcome to level 2!" << endl;
                        system("PAUSE");
                        nLevel++;
                        break;
                                }
                default: {
                        cout << "Error at Levels switch. " << endl;
                        system("PAUSE");
                        nLevel++;
                        break;
                                 }
                }                       //ends Levels switch
                }                       //ends while loop
             

        system("PAUSE");
        return 0;
}



int nTest() {                                                           //Random number out of 10
        cout << rand() % 10 + 1 << endl;

        return 0;
}

/*Saving function*/
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        ofstream saveFile ("save.txt", ios::in | ios::out, ios::trunc);
        saveFile 
                << Name << "\n" 
                << Gender << "\n" 
                << Order << "\n" 
                << Strength << "\n" 
                << Health << "\n" 
                << Mana << "\n" 
                << Defense << "\n"
                << Level << "\n"
                                << XP << "\n";
        saveFile.close();

                return 0;
        }

/*Loading function*/
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        fstream loadFile ("save.txt", ios::in | ios::out);
        loadFile >> Name;
        loadFile >> Gender;
        loadFile >> Order;
        loadFile >> Strength;
        loadFile >> Health;
        loadFile >> Mana;
        loadFile >> Defense;
        loadFile >> Level;
                loadFile >> XP;
        loadFile.close();



                return 0;
        }

/*Combat function*/
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip) {
        int nMenu;
        cout << "Welcome to the tutorial, " << pName << endl;
        cout << "Tutorial Monster: \"You have to beat me to finish this tutorial! \"" << endl;
        cout << "Just pick the options to go throughout the fight. " << endl;
        cout << "1. Status (Check status of fight)" << endl;
        system("PAUSE");
        return 0;
}


Was This Post Helpful? 0
  • +
  • -

#4 Cyrusthebeast  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 11-October 09

Re: Function is not being called

Posted 06 June 2010 - 07:49 PM

View PostImaSexy, on 06 June 2010 - 06:33 PM, said:

your trying to delcare your functions in a header, but then you do not include your header
#include "headerName.h"



Without the header, you could just copy and paste the function definitions into main.cpp


EXAMPLE of using header file


header.h

#ifndef HEADER_H
#define HEADER_H
#include <iostream>

void hello(void)
{
    std::cout<<"HELLO WORLD"<<std::endl;
}

#endif





main.cpp
#include <iostream>
#include "header.h" //including functions here

using namespace std;

int main()
{
    hello();
    cin.ignore();
    cin.get();
    return 0;
}



Well it's not a header file, the second file is functions.cpp, and I was told to NEVER include a .cpp file in a .cpp file.

View Posteker676, on 06 June 2010 - 06:36 PM, said:

I don't know why you have to code files as you are not including anything.

Combine them and it compiles fine.
/*They must have save.txt in same directory as game.exe*/

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

/*Forward Declarations*/
int nTest();
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);

/*Global Stats*/
int nStr=-1;
int nHealth=-1;
int nMana=-1;
int nDefense=-1;
int nLevel=-1;
int nXP=0;
string sName="-1";
string sGender="-1";
string sOrder="-1";

/*Monsters*/
//Tutorial Monster
string sTutName="Tutorial Monster";
int nTutStr=1;
int nTutHealth=8;
int nTutMana=10;
int nTutDefense=1;
string sTutDescrip="A monster used by the game to teach the player how combat works. ";
//TODO: More monsters

int main () {
        srand(time(NULL));                  //seeds the time ONCE (ty Oler1s)
        int nCounter=0;                     //starts the counter for 'for' loops
        int nStartR=1;
        int nInput;
                int genderLoop=1;
                int orderLoop=1;
                int statLoop=1;
                int skipTut=1;
                int tutLoop;
                int F=-1;                                                       //TODO: Replace with the last level     
        
        while (nStartR) {
                cout << "Hello! What would you like to do? " << endl;
                cout << "1. Load Game" << endl;
                cout << "2. New Game (will erase any saved data)" << endl;
                cin >> nInput;
                                system("cls");
                switch(nInput) {
                case 1: {
                        nLoad(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                cout << "Name: " << sName << endl;
                                                cout << "Gender: " << sGender << endl;
                                                cout << "Order: " << sOrder << endl;
                                                cout << "Strength: " << nStr << endl;
                                                cout << "Health: " << nHealth << endl;
                                                cout << "Mana: " << nMana << endl;
                                                cout << "Defense: " << nDefense << endl;
                                                cout << "Level: " << nLevel;
                                                nStartR=0;
                        break;
                                }
                case 2: {
                        cout << "Starting a new game..." << endl;
                                                nLevel=1;
                        cout << "Hello! Welcome to the game! " << endl;
                        cout << "What is your first name? \n" << endl;
                                                cin.ignore(); //http://www.cplusplus.com/forum/beginner/5649/ <- Thanks
                        getline(cin,sName);
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                while (genderLoop) {
                                                cout << "Are you a: " << endl;
                                                cout << "1. Boy" << endl;
                                                cout << "2. Girl" << endl;
                                                cin.clear();
                                                cin >> nInput;
                                                switch(nInput) {
                                                case 1: {
                                                        sGender="Boy";
                                                        genderLoop=0;
                                                        break;
                                                                }
                                                case 2: {
                                                        sGender="Girl";
                                                        genderLoop=0;
                                                        break;
                                                                }
                                                default: {
                                                        cout << "Error in input. Going back";
                                                        cin.clear();
                                                                 }
                                                }                               //ends switch
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                }               //ends genderLoop
                                                system("cls");
                                                cin.clear();
                                                while(orderLoop) {
                                                        cout << "When you were a kid, did you like to: " << endl;
                                                        cout << "1. Be sneaky and steal things from people. " << endl;
                                                        cout << "2. Be up front and personal when there was a conflict at hand. " << endl;
                                                        cout << "3. Be in the back reading books and studying. " << endl;
                                                        cin >> nInput;
                                                        switch(nInput) {
                                                        case 1: {
                                                                sOrder="Rogue";
                                                                cout << "A sneaky, lying Rogue. \nYou lie and cheat and scam other people to make ends meet. " << endl;
                                                                cout << "Rogues tend to have more Defense as they're used to hiding and dodging. " << endl;
                                                                cout << "They also have lower Health as they aren't used to taking hits. " << endl;
                                                                cout << "They've never conditioned themselves to be able to take many hits. " << endl;
                                                                cout << "They also have weaker hits because they've always striken in the dark. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        case 2: {
                                                                sOrder="Warrior";
                                                                cout << "A powerful warrior who uses a broad sword and is not afraid of a challenge. " << endl;
                                                                cout << "Warriors tend to have higher Strength and Life. " << endl;
                                                                cout << "Unfortunately, due to their recklessness, they never studied magic or cared about safety. " << endl;
                                                                cout << "This leads to an inability to use Magic and lower Defense. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        case 3: {
                                                                sOrder="Mage";
                                                                cout << "Your entire life you've spent reading and studying the arcane magics. " << endl;
                                                                cout << "You've learned spells and how to maximize your Mana reserves. " << endl;
                                                                cout << "Due to your lack of physical training, you have very low Strength and Health. " << endl;
                                                                orderLoop=0;
                                                                system("PAUSE");
                                                                break;
                                                                        }
                                                        default: {
                                                                cout << "Unknown option, restarting. ";
                                                                system("cls");
                                                                         }
                                                        }                                               //ends switch statement
                                                }                                                       //ends orderLoop
                                                nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                                
                                                while(statLoop) {                                       //Assigns values based on the order they picked
                                                /*Base Health = 20, Base Mana = 20, Base Strength and Defense = 5*/
                                                        if (sOrder=="Rogue") {
                                                                nHealth=15;
                                                                nMana=20;
                                                                nStr=3;
                                                                nDefense=7;
                                                                statLoop=0;
                                                        }
                                                        else if (sOrder=="Warrior") {
                                                                nHealth=25;
                                                                nMana=0;
                                                                nStr=8;
                                                                nDefense=2;
                                                                statLoop=0;
                                                        }
                                                        else if (sOrder=="Mage") {
                                                                nHealth=15;
                                                                nMana=35;
                                                                nStr=1;
                                                                nDefense=2;
                                                                statLoop=0;
                                                        }
                                                        else
                                                                cout << "Error @ statLoop";
                                                }       //ends statLoop

                                                nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);

                                                nStartR=0;
                                                break;
                                                }                               //ends case 2
                default: {
                        cout << "Unknown option. Restarting..." << endl;
                                                system("cls");
                                 }
                }               //ends first switch
        }                               //ends first while loop

                while (nLevel!=F){
                switch(nLevel) {
                case 1: {
                        system("cls");
                        while (skipTut) {
                        cout << "Welcome to the game! " << endl;
                        cout << "This is just a tutorial to learn the battle system. " << endl;
                        cout << "Do you want to skip it? " << endl;
                        cout << "1. Yes" << endl;
                        cout << "2. No" << endl;
                        cin.clear();
                        cin >> tutLoop;
                                switch(tutLoop) {
                                case 1: {
                                        skipTut=0;
                                        nLevel++;
                                        break;
                                                }
                                case 2: {
                                        skipTut=0;
                                        break;
                                                }
                                default: {
                                        cout << "Unknown option. Restarting...";
                                        system("cls");
                                        cin.clear();
                                                 }
                                }               //ends switch
                        }                       //ends skipTut Loop
                        system("cls");
                        cin.clear();
                        cout << "Welcome to the tutorial. " << endl;
                        cout << "Here you will be placed in combat with a small monster to learn how things work. " << endl;
                        cout << "Press Enter to go into the fight. \n";
                        system("PAUSE");
                        int nCombatTut(string sName, string sGender, string sOrder, int nStr, int nHealth, int nMana, int nDefense, int nXP, string sTutName, int nTutStr, int nTutHealth, int nTutMana, int nTutDefense, string sTutDescrip);
//COMPARING:int nCombatTut(string &pName, string &pGender, string &pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);
                        //TODO: Insert tutorial combat function
                        nLevel++;
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                        break;
                                }
                case 2: {
                        cout << "Welcome to level 2!" << endl;
                        system("PAUSE");
                        nLevel++;
                        break;
                                }
                default: {
                        cout << "Error at Levels switch. " << endl;
                        system("PAUSE");
                        nLevel++;
                        break;
                                 }
                }                       //ends Levels switch
                }                       //ends while loop
             

        system("PAUSE");
        return 0;
}



int nTest() {                                                           //Random number out of 10
        cout << rand() % 10 + 1 << endl;

        return 0;
}

/*Saving function*/
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        ofstream saveFile ("save.txt", ios::in | ios::out, ios::trunc);
        saveFile 
                << Name << "\n" 
                << Gender << "\n" 
                << Order << "\n" 
                << Strength << "\n" 
                << Health << "\n" 
                << Mana << "\n" 
                << Defense << "\n"
                << Level << "\n"
                                << XP << "\n";
        saveFile.close();

                return 0;
        }

/*Loading function*/
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        fstream loadFile ("save.txt", ios::in | ios::out);
        loadFile >> Name;
        loadFile >> Gender;
        loadFile >> Order;
        loadFile >> Strength;
        loadFile >> Health;
        loadFile >> Mana;
        loadFile >> Defense;
        loadFile >> Level;
                loadFile >> XP;
        loadFile.close();



                return 0;
        }

/*Combat function*/
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip) {
        int nMenu;
        cout << "Welcome to the tutorial, " << pName << endl;
        cout << "Tutorial Monster: \"You have to beat me to finish this tutorial! \"" << endl;
        cout << "Just pick the options to go throughout the fight. " << endl;
        cout << "1. Status (Check status of fight)" << endl;
        system("PAUSE");
        return 0;
}



Well I want the functions and main file to be separate for two reasons:

  • I want the files to look neater (has no real effect :P )
  • I want to learn all about using multiple files for when I move onto something more complicated that will damn near REQUIRE multiple files. I figure if I can learn and get rid of simple problems in a stage like this with multiple files, it'll be easier when moving onto something bigger


So if you could please help me grasp the concept while it's in a smaller form.

This post has been edited by Cyrusthebeast: 06 June 2010 - 07:56 PM

Was This Post Helpful? 0
  • +
  • -

#5 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1112
  • View blog
  • Posts: 4,619
  • Joined: 09-June 09

Re: Function is not being called

Posted 06 June 2010 - 08:02 PM

Quote

and I was told to NEVER include a .cpp file in a .cpp file.


yes of course, but you have to include the functions somehow. Put the function prototypes in a separate header file, then define them in there own cpp file. Then include that header file into main.cpp
Was This Post Helpful? 0
  • +
  • -

#6 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Function is not being called

Posted 06 June 2010 - 08:07 PM

Always good to check the tutorials.
If you are having trouble then the chances are others have had trouble before you and possibly someone at DIC has written a tutorial to help them and you.
Here's one worth reading:
http://www.dreaminco...m-to-a-project/
Was This Post Helpful? 0
  • +
  • -

#7 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Function is not being called

Posted 07 June 2010 - 12:13 AM

As a note, there seems to be a formatting issue in your code versus posting here. Part of that may be your use of tabs. In general, you want indentation to be based on spaces, not tabs. I use 4 spaces to signify a tab.

If you have a good IDE or editor, you can specify this. You can indicate that you want tabs to insert spaces. (And you can specify how many spaces you want inserted). Then the editor will manage indentation like normal, but use spaces instead.

I am considering whether I should write up a guide on the C++ compilation model. The thing is, there's already plenty of information on the internet and explaining it. I don't see if it's that the explanations are hard to understand, or that beginners need time to get it.
Was This Post Helpful? 0
  • +
  • -

#8 Cyrusthebeast  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 11-October 09

Re: Function is not being called

Posted 07 June 2010 - 09:41 AM

View PostImaSexy, on 06 June 2010 - 07:02 PM, said:

Quote

and I was told to NEVER include a .cpp file in a .cpp file.


yes of course, but you have to include the functions somehow. Put the function prototypes in a separate header file, then define them in there own cpp file. Then include that header file into main.cpp

+

View Postjanotte, on 06 June 2010 - 07:07 PM, said:

Always good to check the tutorials.
If you are having trouble then the chances are others have had trouble before you and possibly someone at DIC has written a tutorial to help them and you.
Here's one worth reading:
http://www.dreaminco...m-to-a-project/


Well I did what it said and I'm 100% sure I did it right, but I don't see how that would change the situation. To my understanding (correct me if I'm wrong, of course), putting it into the header file will only make it neater but not actually fix (or do anything at all) about the problem. I believe I'm correct because after doing this, I get the exact same problem.

(header.h)
#ifndef MYHEADER_H_INCLUDED
#define MYHEADER_H_INCLUDED
using namespace std;

int nTest();
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP);
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip);


/*Global Stats*/
int nStr=-1;
int nHealth=-1;
int nMana=-1;
int nDefense=-1;
int nLevel=-1;
int nXP=0;
string sName="-1";
string sGender="-1";
string sOrder="-1";

/*Monsters*/
//Tutorial Monster
string sTutName="Tutorial Monster";
int nTutStr=1;
int nTutHealth=8;
int nTutMana=10;
int nTutDefense=1;
string sTutDescrip="A monster used by the game to teach the player how combat works. ";
//TODO: More monsters
#endif


(main.cpp)
/*They must have save.txt in same directory as game.exe*/

#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

#include "header.h"

/*Forward Declarations*/


int main () {
        srand(time(NULL));                  //seeds the time ONCE (ty Oler1s)
        int nCounter=0;                     //starts the counter for 'for' loops
        int nStartR=1;
        int nInput;
		int genderLoop=1;
		int orderLoop=1;
		int statLoop=1;
		int skipTut=1;
		int tutLoop;
		int F=-1;							//TODO: Replace with the last level	
        
        while (nStartR) {
                cout << "Hello! What would you like to do? " << endl;
                cout << "1. Load Game" << endl;
                cout << "2. New Game (will erase any saved data)" << endl;
                cin >> nInput;
				system("cls");
                switch(nInput) {
                case 1: {
                        nLoad(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						cout << "Name: " << sName << endl;
						cout << "Gender: " << sGender << endl;
						cout << "Order: " << sOrder << endl;
						cout << "Strength: " << nStr << endl;
						cout << "Health: " << nHealth << endl;
						cout << "Mana: " << nMana << endl;
						cout << "Defense: " << nDefense << endl;
						cout << "Level: " << nLevel;
						nStartR=0;
                        break;
                                }
                case 2: {
                        cout << "Starting a new game..." << endl;
						nLevel=1;
                        cout << "Hello! Welcome to the game! " << endl;
                        cout << "What is your first name? \n" << endl;
						cin.ignore(); //http://www.cplusplus.com/forum/beginner/5649/ <- Thanks
                        getline(cin,sName);
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						while (genderLoop) {
						cout << "Are you a: " << endl;
						cout << "1. Boy" << endl;
						cout << "2. Girl" << endl;
						cin.clear();
						cin >> nInput;
						switch(nInput) {
						case 1: {
							sGender="Boy";
							genderLoop=0;
							break;
								}
						case 2: {
							sGender="Girl";
							genderLoop=0;
							break;
								}
						default: {
							cout << "Error in input. Going back";
							cin.clear();
								 }
						}				//ends switch
                        nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
                                }		//ends genderLoop
						system("cls");
						cin.clear();
						while(orderLoop) {
							cout << "When you were a kid, did you like to: " << endl;
							cout << "1. Be sneaky and steal things from people. " << endl;
							cout << "2. Be up front and personal when there was a conflict at hand. " << endl;
							cout << "3. Be in the back reading books and studying. " << endl;
							cin >> nInput;
							switch(nInput) {
							case 1: {
								sOrder="Rogue";
								cout << "A sneaky, lying Rogue. \nYou lie and cheat and scam other people to make ends meet. " << endl;
								cout << "Rogues tend to have more Defense as they're used to hiding and dodging. " << endl;
								cout << "They also have lower Health as they aren't used to taking hits. " << endl;
								cout << "They've never conditioned themselves to be able to take many hits. " << endl;
								cout << "They also have weaker hits because they've always striken in the dark. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							case 2: {
								sOrder="Warrior";
								cout << "A powerful warrior who uses a broad sword and is not afraid of a challenge. " << endl;
								cout << "Warriors tend to have higher Strength and Life. " << endl;
								cout << "Unfortunately, due to their recklessness, they never studied magic or cared about safety. " << endl;
								cout << "This leads to an inability to use Magic and lower Defense. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							case 3: {
								sOrder="Mage";
								cout << "Your entire life you've spent reading and studying the arcane magics. " << endl;
								cout << "You've learned spells and how to maximize your Mana reserves. " << endl;
								cout << "Due to your lack of physical training, you have very low Strength and Health. " << endl;
								orderLoop=0;
								system("PAUSE");
								break;
									}
							default: {
								cout << "Unknown option, restarting. ";
								system("cls");
									 }
							}						//ends switch statement
						}							//ends orderLoop
						nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
						
						while(statLoop) {					//Assigns values based on the order they picked
						/*Base Health = 20, Base Mana = 20, Base Strength and Defense = 5*/
							if (sOrder=="Rogue") {
								nHealth=15;
								nMana=20;
								nStr=3;
								nDefense=7;
								statLoop=0;
							}
							else if (sOrder=="Warrior") {
								nHealth=25;
								nMana=0;
								nStr=8;
								nDefense=2;
								statLoop=0;
							}
							else if (sOrder=="Mage") {
								nHealth=15;
								nMana=35;
								nStr=1;
								nDefense=2;
								statLoop=0;
							}
							else
								cout << "Error @ statLoop";
						}	//ends statLoop

						nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);

						nStartR=0;
						break;
						}				//ends case 2
                default: {
                        cout << "Unknown option. Restarting..." << endl;
						system("cls");
                                 }
                }		//ends first switch
        }				//ends first while loop

		while (nLevel!=F){
		switch(nLevel) {
		case 1: {
			system("cls");
			while (skipTut) {
			cout << "Welcome to the game! " << endl;
			cout << "This is just a tutorial to learn the battle system. " << endl;
			cout << "Do you want to skip it? " << endl;
			cout << "1. Yes" << endl;
			cout << "2. No" << endl;
			cin.clear();
			cin >> tutLoop;
				switch(tutLoop) {
				case 1: {
					skipTut=0;
					nLevel++;
					break;
						}
				case 2: {
					skipTut=0;
					break;
						}
				default: {
					cout << "Unknown option. Restarting...";
					system("cls");
					cin.clear();
						 }
				}		//ends switch
			}			//ends skipTut Loop
			system("cls");
			cin.clear();
			cout << "Welcome to the tutorial. " << endl;
			cout << "Here you will be placed in combat with a small monster to learn how things work. " << endl;
			cout << "Press Enter to go into the fight. \n";
			system("PAUSE");
			int nCombatTut(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nXP, sTutName, nTutStr, nTutHealth, nTutMana, nTutDefense, sTutDescrip);
//COMPARING:string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip
			//TODO: Insert tutorial combat function
			nLevel++;
			nSave(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nLevel, nXP);
			break;
				}
		case 2: {
			cout << "Welcome to level 2!" << endl;
			system("PAUSE");
			nLevel++;
			break;
				}
		default: {
			cout << "Error at Levels switch. " << endl;
			system("PAUSE");
			nLevel++;
			break;
				 }
		}			//ends Levels switch
		}			//ends while loop
             

        system("PAUSE");
        return 0;
}


(functions.cpp)
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

int nTest() {                                                           //Random number out of 10
        cout << rand() % 10 + 1 << endl;

        return 0;
}

/*Saving function*/
int nSave(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        ofstream saveFile ("save.txt", ios::in | ios::out, ios::trunc);
        saveFile 
                << Name << "\n" 
                << Gender << "\n" 
                << Order << "\n" 
                << Strength << "\n" 
                << Health << "\n" 
                << Mana << "\n" 
                << Defense << "\n"
                << Level << "\n"
				<< XP << "\n";
        saveFile.close();

		return 0;
        }

/*Loading function*/
int nLoad(string &Name, string &Gender, string &Order, int &Strength, int &Health, int &Mana, int &Defense, int &Level, int &XP) {
        fstream loadFile ("save.txt", ios::in | ios::out);
        loadFile >> Name;
        loadFile >> Gender;
        loadFile >> Order;
        loadFile >> Strength;
        loadFile >> Health;
        loadFile >> Mana;
        loadFile >> Defense;
        loadFile >> Level;
		loadFile >> XP;
        loadFile.close();



		return 0;
        }

/*Combat function*/
int nCombatTut(string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip) {
	int nMenu;
	cout << "Welcome to the tutorial, " << pName << endl;
	cout << "Tutorial Monster: \"You have to beat me to finish this tutorial! \"" << endl;
	cout << "Just pick the options to go throughout the fight. " << endl;
	cout << "1. Status (Check status of fight)" << endl;

	system("PAUSE");
	return 0;
}


As you can see, all global variables are put in the header file. The errors I get are the exact same ones I put earlier :(

View PostOler1s, on 06 June 2010 - 11:13 PM, said:

As a note, there seems to be a formatting issue in your code versus posting here. Part of that may be your use of tabs. In general, you want indentation to be based on spaces, not tabs. I use 4 spaces to signify a tab.

If you have a good IDE or editor, you can specify this. You can indicate that you want tabs to insert spaces. (And you can specify how many spaces you want inserted). Then the editor will manage indentation like normal, but use spaces instead.

I am considering whether I should write up a guide on the C++ compilation model. The thing is, there's already plenty of information on the internet and explaining it. I don't see if it's that the explanations are hard to understand, or that beginners need time to get it.


I've changed my tabs to put in 4 spaces :]
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Function is not being called

Posted 07 June 2010 - 10:02 AM

system("PAUSE");
int nCombatTut(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nXP, sTutName, nTutStr, nTutHealth, nTutMana, nTutDefense, sTutDescrip);
//COMPARING:string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip
//TODO: Insert tutorial combat function
nLevel++;


What's with the int at the beginning there, Sparky?
Was This Post Helpful? 1
  • +
  • -

#10 Cyrusthebeast  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 11-October 09

Re: Function is not being called

Posted 07 June 2010 - 10:13 AM

View PostJackOfAllTrades, on 07 June 2010 - 09:02 AM, said:

system("PAUSE");
int nCombatTut(sName, sGender, sOrder, nStr, nHealth, nMana, nDefense, nXP, sTutName, nTutStr, nTutHealth, nTutMana, nTutDefense, sTutDescrip);
//COMPARING:string pName, string pGender, string pOrder, int &pStrength, int &pHealth, int &pMana, int &pDefense, int &pXP, string MonsterName, int MonsterStr, int MonsterHealth, int MonsterMana, int MonsterDefense, string MonsterDescrip
//TODO: Insert tutorial combat function
nLevel++;


What's with the int at the beginning there, Sparky?

:censored: :censored: :censored: :censored: :censored: :censored: DFJKLSDJFKLJ :censored:
Bah! That's ridiculous! :stupid: :taz:

Thank you! I can't believe it's that simple!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1