Thread: getting a headache

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    176

    getting a headache

    i have been working on this code forever now, i tried taking a break and coming back, that didn't work im getting very frusturated with it here's the code
    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <stdlib.h>
    
    using namespace std;
    
    int Login();
    int Ability();
    int Magic();
    int Weapons();
    int SkillsMenu();
    int AbilityMenu();
    int Player();
    int RaceMenu();
    int CreateFinal();
    //declare functions
    
    
    string PlayerFullName, CharacterName, Class, Race, stop = "yes", Password, Skills, SpecialAbilitys, Racials, whattheytype, endloop;
    int hp, xp, sp = 20, mana, SwitchRace, done, SwitchAbility, WeaponSwitch, MagicSwitch, AblilitySwitch;
    //declare variables
    int skillmenuchoice;
    
    
    int CreateFinal()
    
    {
        cout<<"\nyour player is.... \n \n \n\n\n\n\n";
        cout<<"Player Name: "<<PlayerFullName<<"\nCharacter Name: "<<CharacterName<<"\nclass: "<<Class<<"\nRace: "<<Race<<"\nRacials: "<<Racials<<"\nSkill Points: "<<sp<<"\nSkills\n _______________________________________________\n "<<Skills<<"\nSpecial ablilitys\n _______________________________________________\n"<<SpecialAbilitys<<"\nHitpoints: "<<hp<<"\nmana: "<<mana<<"\nExperience: "<<xp;
        
        string filename = PlayerFullName + ".txt";
        ofstream Playerfile ( filename.c_str() );
    
    
        Playerfile<<"Player Name: "<<PlayerFullName<<"\nCharacter Name: "<<CharacterName<<"\nclass: "<<Class<<"\nRace: "<<Race<<"\nRacials: "<<Racials<<"\nSkill Points: "<<sp<<"\nSkills\n _______________________________________________\n "<<Skills<<"\nSpecial ablilitys\n _______________________________________________\n"<<SpecialAbilitys<<"\nHitpoints: "<<hp<<"\nmana: "<<mana<<"\nExperience: "<<xp;
    
        Playerfile.close(); 
    cin.get();
    return Login();
    }
    //create player text file and print stats to screen
    
    
    
    int Login()
    {
    	sp = 20;
    	cout<<"\nEnter the DM Password or you shall be smited: ";
    	cin>>Password;
        cin.ignore();
    	if (Password == "god") {
    		stop = "";
    		cout<<"\n\nyou truly are an evil gm\n\n Would you like to create a Player?(yes or no): ";
    		cin>>stop;
    	    cin.ignore();
    		if (stop == "yes")
    			return Player();
    
    
                 cout<<"WITH DARKNESS I CAUSE DEATH!!!!!!!!\n\n\n\n (this is where you die)\n";
                 system("exit");
    }
    //log in to use prog.
    
    
    int Player()
    {
    system("cls");
        cout<<"\nEnter Player Full Name: ";
        cin>>PlayerFullName;
        cin.ignore();    
        //player name
       
        cout<<"\nEnter Character Name: ";
        cin>>CharacterName;
        cin.ignore();   
        //character name
        
        cout<<"\nEnter Class: ";
        cin>>Class;
        cin.ignore();    
        //class name
        
        cout<<"\nHow much Experience?: ";
        cin>>xp;
        cin.ignore();  
        
        //experience
        
        cout<<"\nplayable races\n Good Aligned\n________\n(1)Human\n(2)Gnome\n(3)Halfling\n(4)Dwarf\n(5)Elf\n(6)Animal Folk\n(7)Seelie Fae\n\nEvil Aligned\n________\n(1)Human\n(8)Kobold\n(9)Goblin\n(10)Orc\n(11)Dark Elf\n(6)Animal Folk\n(12)Unseelie Fae \ntype the numbers that are next to the race name, to select that race.\n";            
        cout<<"\nEnter Race: ";
        cin>>SwitchRace;
        cin.ignore();
    return RaceMenu();
    }
    
    int RaceMenu()
    {
    
        switch ( SwitchRace )
        {
            case 1:
            cout<<"\n you chose Human +2 ability points";
            Race = "Human";
            sp = sp + 2;
            break;
            
        case 2:
        cout<<"\n you chose Gnome 1/2 cost craft";
        Race = "Gnome";
        Racials = "1/2 cost craft";
        break;
        
            case 3:
            cout<<"\n you chose Halfling 1/2 cost thrown weapons";
            Race = "Halfling";
            Racials = "1/2 cost thrown weapons";
            break;
                
        case 4:
        cout<<"\n you chose Dwarf +2 hp";
        Race = "Dwarf";
        hp = hp + 2;
        sp = 12;
        break;
        
            case 5:
            cout<<"\n you chose Elf +2 mana";
            Race = "Elf";
            mana += 2;
            sp = 12;
            break;
        
        case 6:
        cout<<"\n you chose Animal Folk";
        Race = "Animal Folk";
        Racials = "See Dm";
        break;
       
           case 7:
           cout<<"\n you chose Seelie Fae +2 mana";
           Race = "Seelie Fae";
           mana += 2;
           sp = 12;
           break;
       
        case 8:
        cout<<"\n you chose Kobold 1/2 cost trap making";
        Race = "Kobold";
        Racials = "1/2 cost trap making";
        break;
        
            case 9:
            cout<<"\n you chose Goblin 1/2 Cost Spear";
            Race = "Goblin";
            Racials = "1/2 Cost Spear";
            break;
        
        case 10:
        cout<<"\n you chose Orc 1/2 Cost Two-Handed";
        Race = "Orc";
        Racials = "1/2 Cost Two-Handed";
        break;
        
            case 11:
            cout<<"\n you chose Dark Elf +2 mana";
            Race = "Dark Elf";
            mana += 2;
            sp = 12;
            break;
        
        case 12:
        cout<<"\n you chose Unseelie Fae +2 mana";
        Race = "Unseelie Fae";
        mana += 2;
        sp = 12;
        break;
       
       default:
       cout<<"\n that is not a Race! try again: ";
       cin>>SwitchRace;
       cin.ignore();
       break;
         }
    return AbilityMenu();
    }
    //race selection
    
    
    int AbilityMenu()
    {
    system("cls");
    cout<<"\n You have "<<sp<<" skill points to spend on Skills, Abilitys, Mana, and hit points\n type (skills) to see a list of skills: "; 
    string checkifstring;
    cin>>checkifstring;
    if (checkifstring == "skills"){
    return SkillsMenu();
    }	
    
    
    int SkillsMenu()
    {
    cout<<"\n(1)Weapon skills\n(2)Magic skills\n(3)Abilitys\nType the number to access the Skills menu of your choice, you have  "<<sp<<" Skill Points left: ";
    cin>>skillmenuchoice;
    
    	switch ( skillmenuchoice )
    	{
    	case 1:
    		return Weapons();
    	break;
    	case 2:
    		return Magic();
    	break;
    	case 3:
    		return Ability();
    	break;
    
    	default:	
    		cout<<"Wrong Choice, Try Again";
    
    		return SkillsMenu();
    	break;
    	
     }
    //skill menu
    
    
    int Weapons()
    {
    system("cls");
    cout<<"\nweapon skills are\n___________________\n(1)Dagger cost = 2 sp\n(2)Short sword = 3 sp\n(3)Long Sword = 4 sp\n(4)Two Handed Sword = 5 sp\n(5)lub = 2 sp\n(6)Staff = 3 sp\n(7)Thrown = 2 sp\n(8)Shield = 2 sp\n(9)Ambidexterous = 3 sp\n(10)Strong = 5 sp\n(11)Sneak Attack = 4 sp\n(12)Sap(waylay) = 4 sp\n(13)Extra Damage = 12 sp\n(14)Archery = 3 sp\ntype the number of the skill you want: ";
        cin>>WeaponSwitch;
       
            switch ( WeaponSwitch )
            {
        
            case 1:
            
            sp -=  2;//dagger
            break;
            
            
            case 2:
            
            sp -=  3;//short sword
            break;
            
            
            case 3:
            
            sp -=  4;//long sword
            break;
            
            
            case 4:
            
            sp -=  5;//two handed sword
            break;
            
            
            case 5:
            
            sp -=  2;//club
            break;
            
            
            case 6:
            
            sp -=  3;//staff
            break;
            
            
            case 7:
            sp -=  2;//thrown
            break;
            
            
            case 8:
            
            sp -=  2;//shield
            break;
            
            
            case 9:
            
            sp -=  3;//ambidexturous
            break;
            
            
            case 10:
            
            sp -= 5;//strong
            break;
            
            
            case 11:
            
            sp -=4;//sneak attack
            break;
            
            
            case 12:
            
            sp -=4;//sap (waylay)
            break;
            
            
            case 13:
            
            sp -=12;//extra dammage
            break;
            
            
            case 14:
            
            sp -=2;//archery
            break;
            
            default:
            cout<<"That is not a Weapon skill, type a weapon skill: ";
    	    return Weapons();
            break;
            } 
      //weapons skills      
    int Magic()
    {
    system("cls");
    }
    //magic skills
    
    int Ability()
    {
    system("cls");
    }
    //abilitys
    
    if ( sp < 1)
    {
    return CreateFinal();
    }
    
    
    
    int main()
    {
    system("color 0a");
    system("cls");
    
    return Login();
    
    
    }
    I know posting all your code is frowned upon, but i dont know where the problem is i get crazy parse errors, and also i know the system commands are frowned upon also, but that was something my friend did when he tried to work on it, and i like the clear effect anyways anyways any help anyone can give me would be appreciated.... i know im gonna get flamed for this

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Did you have a question?


    Match your braces and use good indentation. Here's a freebie starter: int Login().
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User LiNeAr's Avatar
    Join Date
    Aug 2005
    Posts
    31
    I don't feel like looking through it right now. But some advice I could give you would be to use the header #include <cstdlib> instead of #include<stdlib.h> (it's out of date). Also, another tip (too late for you now), would be to take the coding in steps. Code some stuff first, then compile, if it compiles fine, move on. That's about all I can give you, sorry.
    IDE: Microsoft Visual C++ .net Standard 2003

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    my problem is i cant figure out where the braces are supposed to go i try and i just end up messing something else up

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Beautification 1:
    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <stdlib.h>
    
    using namespace std;
    
    int Login();
    int Ability();
    int Magic();
    int Weapons();
    int SkillsMenu();
    int AbilityMenu();
    int Player();
    int RaceMenu();
    int CreateFinal();
    //declare functions
    
    
    string PlayerFullName, CharacterName, Class, Race, stop = "yes", Password, Skills, SpecialAbilitys, Racials, whattheytype, endloop;
    int hp, xp, sp = 20, mana, SwitchRace, done, SwitchAbility, WeaponSwitch, MagicSwitch, AblilitySwitch;
    //declare variables
    int skillmenuchoice;
    
    
    int CreateFinal()
    
    {
       cout<<"\nyour player is.... \n \n \n\n\n\n\n";
       cout<<"Player Name: "<<PlayerFullName<<"\nCharacter Name: "<<CharacterName<<"\nclass: "<<Class<<"\nRace: "<<Race<<"\nRacials: "<<Racials<<"\nSkill Points: "<<sp<<"\nSkills\n _______________________________________________\n "<<Skills<<"\nSpecial ablilitys\n _______________________________________________\n"<<SpecialAbilitys<<"\nHitpoints: "<<hp<<"\nmana: "<<mana<<"\nExperience: "<<xp;
    
       string filename = PlayerFullName + ".txt";
       ofstream Playerfile ( filename.c_str() );
    
    
       Playerfile<<"Player Name: "<<PlayerFullName<<"\nCharacter Name: "<<CharacterName<<"\nclass: "<<Class<<"\nRace: "<<Race<<"\nRacials: "<<Racials<<"\nSkill Points: "<<sp<<"\nSkills\n _______________________________________________\n "<<Skills<<"\nSpecial ablilitys\n _______________________________________________\n"<<SpecialAbilitys<<"\nHitpoints: "<<hp<<"\nmana: "<<mana<<"\nExperience: "<<xp;
    
       Playerfile.close(); 
       cin.get();
       return Login();
    }
    //create player text file and print stats to screen
    
    
    
    int Login()
    {
       sp = 20;
       cout<<"\nEnter the DM Password or you shall be smited: ";
       cin>>Password;
       cin.ignore();
       if ( Password == "god" )
       {
          stop = "";
          cout<<"\n\nyou truly are an evil gm\n\n Would you like to create a Player?(yes or no): ";
          cin>>stop;
          cin.ignore();
          if ( stop == "yes" )
             return Player();
    
    
          cout<<"WITH DARKNESS I CAUSE DEATH!!!!!!!!\n\n\n\n (this is where you die)\n";
          system("exit");
       }
    //log in to use prog.
    
    
       int Player()
       {
          system("cls");
          cout<<"\nEnter Player Full Name: ";
          cin>>PlayerFullName;
          cin.ignore();    
        //player name
    
          cout<<"\nEnter Character Name: ";
          cin>>CharacterName;
          cin.ignore();   
        //character name
    
          cout<<"\nEnter Class: ";
          cin>>Class;
          cin.ignore();    
        //class name
    
          cout<<"\nHow much Experience?: ";
          cin>>xp;
          cin.ignore();  
    
        //experience
    
          cout<<"\nplayable races\n Good Aligned\n________\n(1)Human\n(2)Gnome\n(3)Halfling  \n(4)Dwarf\n(5)Elf\n(6)Animal Folk\n(7)Seelie Fae\n\nEvil Aligned\n________\n(1)Human\n(8)Kobold\n(9)Goblin\  n(10)Orc\n(11)Dark Elf\n(6)Animal Folk\n(12)Unseelie Fae \ntype the numbers that are next to the race name, to select that race.\n";            
          cout<<"\nEnter Race: ";
          cin>>SwitchRace;
          cin.ignore();
          return RaceMenu();
       }
    
       int RaceMenu()
       {
    
          switch ( SwitchRace )
          {
          case 1:
             cout<<"\n you chose Human +2 ability points";
             Race = "Human";
             sp = sp + 2;
             break;
    
          case 2:
             cout<<"\n you chose Gnome 1/2 cost craft";
             Race = "Gnome";
             Racials = "1/2 cost craft";
             break;
    
          case 3:
             cout<<"\n you chose Halfling 1/2 cost thrown weapons";
             Race = "Halfling";
             Racials = "1/2 cost thrown weapons";
             break;
    
          case 4:
             cout<<"\n you chose Dwarf +2 hp";
             Race = "Dwarf";
             hp = hp + 2;
             sp = 12;
             break;
    
          case 5:
             cout<<"\n you chose Elf +2 mana";
             Race = "Elf";
             mana += 2;
             sp = 12;
             break;
    
          case 6:
             cout<<"\n you chose Animal Folk";
             Race = "Animal Folk";
             Racials = "See Dm";
             break;
    
          case 7:
             cout<<"\n you chose Seelie Fae +2 mana";
             Race = "Seelie Fae";
             mana += 2;
             sp = 12;
             break;
    
          case 8:
             cout<<"\n you chose Kobold 1/2 cost trap making";
             Race = "Kobold";
             Racials = "1/2 cost trap making";
             break;
    
          case 9:
             cout<<"\n you chose Goblin 1/2 Cost Spear";
             Race = "Goblin";
             Racials = "1/2 Cost Spear";
             break;
    
          case 10:
             cout<<"\n you chose Orc 1/2 Cost Two-Handed";
             Race = "Orc";
             Racials = "1/2 Cost Two-Handed";
             break;
    
          case 11:
             cout<<"\n you chose Dark Elf +2 mana";
             Race = "Dark Elf";
             mana += 2;
             sp = 12;
             break;
    
          case 12:
             cout<<"\n you chose Unseelie Fae +2 mana";
             Race = "Unseelie Fae";
             mana += 2;
             sp = 12;
             break;
    
          default:
             cout<<"\n that is not a Race! try again: ";
             cin>>SwitchRace;
             cin.ignore();
             break;
          }
          return AbilityMenu();
       }
    //race selection
    
    
       int AbilityMenu()
       {
          system("cls");
          cout<<"\n You have "<<sp<<" skill points to spend on Skills, Abilitys, Mana, and hit points\n type (skills) to see a list of skills: "; 
          string checkifstring;
          cin>>checkifstring;
          if ( checkifstring == "skills" )
          {
             return SkillsMenu();
          }
    
    
          int SkillsMenu()
          {
             cout<<"\n(1)Weapon skills\n(2)Magic skills\n(3)Abilitys\nType the number to access the Skills menu of your choice, you have  "<<sp<<" Skill Points left: ";
             cin>>skillmenuchoice;
    
             switch ( skillmenuchoice )
             {
             case 1:
                return Weapons();
                break;
             case 2:
                return Magic();
                break;
             case 3:
                return Ability();
                break;
    
             default: 
                cout<<"Wrong Choice, Try Again";
    
                return SkillsMenu();
                break;
    
             }
    //skill menu
    
    
             int Weapons()
             {
                system("cls");
                cout<<"\nweapon skills are\n___________________\n(1)Dagger cost = 2 sp\n(2)Short sword = 3 sp\n(3)Long Sword = 4 sp\n(4)Two Handed Sword = 5 sp\n(5)lub = 2 sp\n(6)Staff = 3 sp\n(7)Thrown = 2 sp\n(8)Shield = 2 sp\n(9)Ambidexterous = 3 sp\n(10)Strong = 5 sp\n(11)Sneak Attack = 4 sp\n(12)Sap(waylay) = 4 sp\n(13)Extra Damage = 12 sp\n(14)Archery = 3 sp\ntype the number of the skill you want: ";
                cin>>WeaponSwitch;
    
                switch ( WeaponSwitch )
                {
                
                case 1:
    
                   sp -=  2;//dagger
                   break;
    
    
                case 2:
    
                   sp -=  3;//short sword
                   break;
    
    
                case 3:
    
                   sp -=  4;//long sword
                   break;
    
    
                case 4:
    
                   sp -=  5;//two handed sword
                   break;
    
    
                case 5:
    
                   sp -=  2;//club
                   break;
    
    
                case 6:
    
                   sp -=  3;//staff
                   break;
    
    
                case 7:
                   sp -=  2;//thrown
                   break;
    
    
                case 8:
    
                   sp -=  2;//shield
                   break;
    
    
                case 9:
    
                   sp -=  3;//ambidexturous
                   break;
    
    
                case 10:
    
                   sp -= 5;//strong
                   break;
    
    
                case 11:
    
                   sp -=4;//sneak attack
                   break;
    
    
                case 12:
    
                   sp -=4;//sap (waylay)
                   break;
    
    
                case 13:
    
                   sp -=12;//extra dammage
                   break;
    
    
                case 14:
    
                   sp -=2;//archery
                   break;
    
                default:
                   cout<<"That is not a Weapon skill, type a weapon skill: ";
                   return Weapons();
                   break;
                } 
      //weapons skills      
                int Magic()
                {
                   system("cls");
                }
    //magic skills
    
                int Ability()
                {
                   system("cls");
                }
    //abilitys
    
                if ( sp < 1 )
                {
                   return CreateFinal();
                }
    
    
    
                int main()
                {
                   system("color 0a");
                   system("cls");
    
                   return Login();
    
    
                }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok, yeah thats much clearer code and it looks like it should run fine to me, but i still get a bunch of parse errors
    Last edited by sreetvert83; 08-12-2005 at 10:10 PM.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Code:
    int SkillsMenu()
    {
    cout<<"\n(1)Weapon skills\n(2)Magic skills\n(3)Abilitys\n
    Type the number to access the Skills menu of your choice, you have  "<<sp<<" Skill Points left: ";
    cin>>skillmenuchoice;
    
    	switch ( skillmenuchoice )
    	{
    	case 1:
    		return Weapons();
    	break;
    	case 2:
    		return Magic();
    	break;
    	case 3:
    		return Ability();
    	break;
    
    	default:	
    		cout<<"Wrong Choice, Try Again";
    
    		return SkillsMenu();
    	break;
    	
     }
    Where is the closing bracket? Parse errors are usually caused by missing brackets or semi-colons (as far as I'm aware). The error window will usually help you locate a general area where you should be looking (specific lines), though sometimes these errors carry on to some later line and it's not much help.

    A little tip: As dave_sinkula mentioned, indentation is great in helping you identify these problems
    Code:
    int SkillsMenu()
    {
    	cout<<"\n(1)Weapon skills\n(2)Magic skills\n(3)Abilitys\n
    		Type the number to access the Skills menu of your choice, you have  "<<sp<<" Skill Points left: ";
    	cin>>skillmenuchoice;
    
    	switch ( skillmenuchoice )
    	{
    	case 1:
    		return Weapons();
    		break;
    	case 2:
    		return Magic();
    		break;
    	case 3:
    		return Ability();
    		break;
    	default:	
    		cout<<"Wrong Choice, Try Again";
    		return SkillsMenu();
    		break;
    	//Obvious to see you're missing the bracket here...
    }
    Also, when you post code, it'll make the window as wide as your longest line...it makes your posts a touch easier to read if you break up long code lines into smaller lines (I.e. what I did with that first cout).

    EDIT:
    Sadly, most of your debugging time won't be coding, it'll be trying to find where you missed the damn semi-colon.

    EDIT2:
    Oh yeah, and you want to be careful with global variables, generally it's best to use them as little as possible (none is best). I'm talking about something like your "Password" variable, which is used only in one of your functions; Login(). It would be a good idea to just make that a member variable of that function.
    Last edited by Epo; 08-12-2005 at 10:12 PM.
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i know, stupid semi-colons , and brackets...... grrr
    EDIT: woot down to one parse error.... thanks, but im sure there will be more questions to follow
    Last edited by sreetvert83; 08-12-2005 at 10:21 PM.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Take a close look towards the middle-end of your code here...
    Code:
     //weapons skills      
                int Magic()
                {
                   system("cls");
                }
    //magic skills
    
                int Ability()
                {
                   system("cls");
                }
    //abilitys
    
                if ( sp < 1 )
                {
                   return CreateFinal();
                }
    
    
    
                int main()
                {
                   system("color 0a");
                   system("cls");
    
                   return Login();
    
    
                }
    What does that bolded code belong to? (There is no closing bracket before main(). It looks to me like those last functions (AbilityMenu(), SkillsMenu(), and Weapons()) are all missing closing braces...
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok thanks i got that all running the right way but now i am stuck with another problem.... i want to have the choices made in the skill selections to be saved, and printed both to the screen and the text files, i have talked to a few of my friends and they said the switch case isn't the best way to acheive this, so i guess my code will change a lot more now. I was just wondering if anyone could explain a way to do this, or point me to a good tutorial on the subject. thanks for all the help this far
    Last edited by sreetvert83; 08-15-2005 at 04:01 PM.

  11. #11
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    There's nothing wrong with a switch statement...here's a small example:
    Code:
    typedef enum UserChoice
    {
    	Sword = 1;
    	Armor = 2;
    }UserChoice;
    
    void ChooseSkill(void)
    {
    	cout<<"\n(1)Sword\n(2)Armor\n
    		Type the number to access the Skills menu of your choice, you have  "<<sp<<" Skill Points left: ";
    	cin>>Choice;
    
    	switch(Choice)
    	{
    	case Sword:
    		//Throw in code that displays to the screen here
    
    		//Throw in code that opens/writes/closes a file here
    
    		break;
    
    	case Armor:
    		//Throw in code that displays to the screen here
    
    		//Throw in code that opens/writes/closes a file here
    
    		break;
    
    	default:
    
    		//Throw in an error message to pick another choice.
    		//Based on your mood, you can use a loop here to 
    		//go back to the start, or just return with nothing.
    
    	}
    There's a small starter...the rest is for you to fill in. Like I said, a switch statement is the way to go (unless I'm missing something...)
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    but i wanted it to print it all in one text file and print it on the screen at the end, i could append to the file, but i wnated the skills printed in the skills part of the file and i wanted it to print the skills selection in the end also, so i guess im asking is there anyway to save the selection and print it in CreateFinal()?

  13. #13
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Okay, I see now

    My first idea would be to create a class for the player
    Code:
    class CPlayer
    {
    public:
    	CPlayer();
    	virtual ~CPlayer();
    
    	//Abilities - Should be initially set to 0 in constructor, and increase values as
    	//skill improves
    	int Heal, Regeneration; //etc.
    
    	//Spells - Should be initially set to false in constructor, and true during creation
    	bool KnowsFireball, KnowsFrostyball; //etc.
    	//Alternatively, make them ints, set to 0 in constructor, and increase value as
    	//skill improves
    
    	//Weapons - Should be initially set to 0 in constructor, and adjusted during creation
    	int Longsword, Shield, Armour; //Etc.
    };
    Then, based on this class, you can extract the proper information during your CreateFinal() function. This way, you can store the player's stats during the game too, and you're not required to open a text file each time you want to find out whether the player knows Fireball or not.

    And of course, you can throw in your own ways of measuring/keeping track of skills, but classes are generally the way to go whenever you want to store information about an object.
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    I understand what your saying, and i get the general idea, but classes were never my strong point, so i guess ill have to read the tutorial on this site to understand them i think ill do that now

  15. #15
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    It took me a while to get into the habit of classes (oh, about 3 years), but then once I did, everything became a lot easier to manage. It'll probably take a couple of tries of "This is useless, I'm gonna do it without classes", then trying them again in a week, then quitting, then trying again, until you finally realize how it's all actually not as complicated as it seems (well, it did for me anyways).

    Classes are very good (if you're familiar with structs, they're practically the same thing, with minor changes) and the sooner you get your head around them, the easier you'll find writing code to be for projects such as this.
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. libusb headache
    By cbee in forum C Programming
    Replies: 2
    Last Post: 12-02-2008, 08:27 PM
  2. Headache error message
    By Strait in forum C++ Programming
    Replies: 6
    Last Post: 01-31-2005, 03:48 PM
  3. My headache
    By Morgan in forum C Programming
    Replies: 7
    Last Post: 12-03-2002, 03:33 AM
  4. Pointers + Arrays = Headache
    By Estauns in forum C++ Programming
    Replies: 7
    Last Post: 11-22-2001, 06:53 PM
  5. Linked List headache
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 09-23-2001, 06:42 PM