code help

This is a discussion on code help within the C++ Programming forums, part of the General Programming Boards category; I have a large program i need help with, what my program does is makes a character and saves it ...

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

    code help

    I have a large program i need help with, what my program does is makes a character and saves it as a text file i need i have a set variable for skill points here is my code (with most of it cut out for it has no relivance to my problem so ill make a small program that will have my problem in it
    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    int main()
    {
    string spend;
    int SkillPoints = 12, Switch;
    cout<<" You have "<<SkillPoints<<" Points to spend do you want to spend them?(yes or no): ";
    cin>>spend;
    if (spend == "Yes")
    {
    cout<<"\n(1)magic or (2)weapons\n\n weapons cost 2 skill points magic cost 4 skill points";
    cin>>Switch;
    cin.ignore();
                switch ( Switch )
          {
                case 1:
                {
                SkillPoints = SkillPoints - 4;
                break;
                }
                case 2:
                {
                SkillPoints = SkillPoints - 2;
                break;
                }
                default:
                {
                cout<<"you can only type 1 or 2: ";
                cin>>Switch;
                break;
                }
           }
           cout<<"\nSpend More points? you have "<<SkillPoints<<" Points left(yes or no): ";
           cin>>Switch;
           cin.ignore();
        }  
      
    else
     {
     cout<<"\nGoodbye";
     cin.get();
     }
     
     return 0;
    }
    
    {
    what i want it to do is when you choose magic i want it to subtract 4 from SkillPoints And then tell you you have 8 points left you can spend them on magic or weapons then subtract the right amount, when there are no more points to spend or not enough to spend i want it to print your choices ie. magic magic weapons. if i need to be clearer or put my actual program on i will its just i didn't want to fill this up with code not relivent to my problem

    I've been working on this program for a week and im gettin tired and i have been making little mistakes like typos im sure everyone has had days like this so forgive me if im not clear

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Don't double-post, bud.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i pressed post then went clicked stop on my brouser so i could add a little more then sent it i didn't realize it would send it twice, but thanks for your rudeness

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>thanks for your rudeness
    You're welcome.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Not quite sure I understand your problem, but I did note the following:

    You never loop. Perhaps you want to ask if the user wants to spend more points, then let them re-enter the spend variable, and loop back to the top if the answer is "Yes". In this case, a while-loop seems to be appropriate, instead of the plain if-statement.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok, that will make it loop, but how do i make it so it says everything you spent the points on say you spent it on magic 3 times so now you have 0 points i want it to print magic magic magic (on my actual program there are more choices so i want it to say each choice you make)

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Have variables to keep track of how much 'magic' and 'weapons' were purchased, perhaps.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i thought of that.... maybe i shouild post all of my code but forgive me i started making alterations to it when i found this problem and the code got kind of messy anyways here it is

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    int main()
    {
    
    string PlayerFullName, CharacterName, Class, Race, stop = "yes", Password, Skills, SpecialAbilitys, Racials, whattheytype;
    int hp, xp, sp = 12, mana, SwitchRace, done, SwitchAbility, WeaponSwitch, MagicSwitch, AblilitySwitch;
    //declare variables
    
    
    cout<<"enter dm password or you shall be smited!: ";
    cin>>Password;
    cin.ignore();
    if (Password == "god")
    //password protected
    
    {
       cout<<"\n\nyou truly are an evil gm\n\n Would you like to create a Player?(yes or no): ";
       cin>>stop;
       cin.ignore();
       
    while (stop == "yes")
        
        //main loop
        {
        cout<<"\nEnter Player Full Name: ";
        getline(cin, PlayerFullName, '\n');
        }
        //player name
        {
        cout<<"\nEnter Character Name: ";
        getline(cin, CharacterName, '\n');
        }
        //character name
        {
        cout<<"\nEnter Class: ";
        getline(cin, Class, '\n');
        }
        //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();
        }
        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 = 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 = 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 = mana + 2;
            sp = 12;
            break;
        
        case 12:
        cout<<"\n you chose Unseelie Fae +2 mana";
        Race = "Unseelie Fae";
        mana = mana + 2;
        sp = 12;
        break;
       
       default:
       cout<<"\n that is not a Race! try again: ";
       cin>>SwitchRace;
       cin.ignore();
       break;
         }
         //races
         
         
         
         {
       cout<<"\n You have "<<sp<<" skill points to spend on skills, abilitys, mana, and hit points type (skills) to see a list of skills: "; 
        cin>>whattheytype;
        cin.ignore();
        }
        if (whattheytype == "skills")
        {
        cout<<"\n(1)Weapon skills\n(2)Magic skills\n(3)Abilitys\n";
        switch ( SwitchAbility )
        
        
        case 1:
        {
        cout<<"\nweapon skills are\n___________________\nDagger cost = 2 sp\nShort sword = 3 sp\nLong Sword = 4 sp\nTwo Handed Sword = 5 sp\nClub = 2 sp\nStaff = 3 sp\nThrown = 2 sp\nShield = 2 sp\nAmbidexterous = 3 sp\nStrong = 5 sp\nSneak Attack = 4 sp\nSap(waylay) = 4 sp\nExtra Damage = 12 sp\nArchery = 3 sp\n";
            
            switch ( WeaponSwitch )
            {
            
            case 1:
            {
            sp - 2;
            break;
            }
            
            case 2:
            {
            sp - 3;
            break;
            }
            
            case 3:
            {
            sp - 4;
            break;
            }
            
            case 4:
            {
            sp - 5;
            break;
            }
            
            case 5:
            {
            sp - 2;
            break;
            }
            
            case 6:
            {
            sp - 3;
            break;
            }
            
            case 7:
            {
            sp - 2;
            break;
            }
            
            case 8:
            {
            sp - 2;
            break;
            }
            
            case 9:
            {
            sp - 3;
            break;
            }
            
            case 10:
            {
            sp - 5;
            break;
            }
            
            case 11:
            {
            sp - 4;
            break;
            }
            
            case 12:
            {
            sp - 4;
            break;
            }
            
            case 13:
            {
            sp - 12;
            break;
            }
            
            case 14:
            {
            sp - 2;
            break;
            }
        cout<<"\nSpend More points? you have "<<sp<<" Points left(yes or no): ";
        cin>>whattheytype;
        cin.ignore();    
        break;
        }
        //weapon skills
        
        
        case 2:
        {
        cout<<"\nMagic skills are\n___________________\nMana Points	= 2 sp\nRitual = 4 sp\nRead Magic = 1 sp\nMass Heal = 9 sp";
        break;
        }
        case 3:
        {
        cout<<"\nAbilitys are\n___________________\nHeal = 2 sp\nRead/Write = 1 sp\nLock Pick = 3 sp\nDisable Trap = 3 sp\nArmor Craft = 3 sp\nLore = 1 sp\nThrown = 2 sp\nHit Points = 1 sp\nDodge = 5 sp\nSneak Attackv = 4 sp\nCreate Potion = 4 sp\nCraftsman = 2 sp sp\n";
        break;
        }
        default:
        {
        cout<<"\nThat is not a skill try again: ";
        cin>>whattheytype;
        cin.ignore();
        break;
        }
        
        if (whattheytype != "skills")
        {
        cout<<"\nYou have "<<sp<<" Skill points left to spend!";
        }
        // skill spending
        
        
        
        {
         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;
        cout << "\nCreate another Character?(yes or no): "; 
        cin>>stop;
        cin.ignore();
         }
        // player file
        
        
        if (Password != "god") 
        {
        cout<<"WITH DARKNESS I CAUSE DEATH!!!!!!!!\n\n\n\n (this is where you die)";
        //wrong password
        }
    {
    cout<<"\n\n\n\n\n\n\n\nGoodBye!";
    cin.get();
    
    return 0;
    }

    thats it forgive me on how messy it is

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21