Major help with my code...

This is a discussion on Major help with my code... within the C++ Programming forums, part of the General Programming Boards category; Hi im new here, and I just need a bit of help. When I compile this and get to the ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    Major help with my code...

    Hi im new here, and I just need a bit of help.
    When I compile this and get to the part where i'm meant to type in a word, (Page) It just skips to the end and says: "Press any key to continue".

    Any help?

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        float STR;
        float DEX;
        float WA;
        int MIN;
        int MAX;
        float COMBO;
        float PANIC;
        float SkillMastery;
        float POWER;
        float WDEF;
        float ORBS;
        float SLASHB;
        float RAGE;
        float JOB;
        float JOBB;
        float WEAPON;
        float Page;
        float Fighter;
        float Spearman;
        float NormalWarrior;
        float TwoHandedMace;
        float OneHandedMace;
        float OneHandedSword;
        float TwoHandedSword;
        float age;
        cout<<"Welcome to John's axe warrior damage calculator v.0.1";
        cout<<"---------------------------------------Note: 'a' for max or min means 1 damage or 'miss'---------------------------------------------------------------------------------------------------";
        
        cout<<"Enter STR:";
        cin>>STR;
        cout<<"Enter DEX:";
        cin>>DEX;
        cout<<"Enter Weapon Attack:";
        cin>>WA;
        cout<<"Enter Skill Mastery:";
        cin>>SkillMastery;
        cout<<"Power Strike? (1.14 - 2.60):";
        cin>>POWER;
        cout<<"Slash blast? (.57 - 1.3):";
        cin>>SLASHB;
        cout<<"Monsters Defence?";
        cin>>WDEF;
        cout<<"Type of warrior? (Normal Warrior, Fighter, Spearman, Page)";
        cin>>JOB;
        if ( JOB = Page ) 
        {                 
                          cout<<"Type of weapon? (2hSword, 2hMace, 1hSword, 1hMace...)";
                          cin>>WEAPON;
                          if ( WEAPON = TwoHandedSword ) 
                        {        
                                 MIN = ((((STR*0.9*SkillMastery*3.4) + DEX)/100 * WA)) -WDEF;
                                 MAX = ((((STR*4.6) + DEX)/100 * WA)) -WDEF;
        
                                 cout<<"Minimum damage (normal slash):";
                                 cout<<MIN<<endl;
                                 cout<<"Maximum damage (normal slash):";
                                 cout<<MAX<<endl;
        
                                 system ("PAUSE");
                                 int MINP;
                                 int MAXP;
                                 MINP = ((MIN+WDEF)*POWER)-WDEF;
                                 MAXP = ((MAX+WDEF)*POWER)-WDEF;
                                 cout<<"Minimum damage with power strike:";
                                 cout<<MINP<<endl;
                                 cout<<"Maximum damage with power strike:";
                                 cout<<MAXP<<endl;   
                                 system ("PAUSE");
                                 int MINSB;
                                 int MAXSB;
                                 MINSB = ((MIN+WDEF)*SLASHB)-WDEF;
                                 MAXSB = ((MAX+WDEF)*SLASHB)-WDEF;    
                                 cout<<"Minimum damage with slash blast:";
                                 cout<<MINSB<<endl;
                                 cout<<"Maximum damage with slash blast:";
                                 cout<<MAXSB<<endl;
        
                                 system ("PAUSE");
                                 return 0;   
                         }
                                 else if ( WEAPON = TwoHandedMace ) 
                         {            
                                 MIN = ((((STR*0.9*SkillMastery*3.2) + DEX)/100 * WA)) -WDEF;
                                 MAX = ((((STR*4.8) + DEX)/100 * WA)) -WDEF;
        
                                 cout<<"Minimum damage (normal slash):";
                                 cout<<MIN<<endl;
                                 cout<<"Maximum damage (normal slash):";
                                 cout<<MAX<<endl;
        
                                 system ("PAUSE");
                                 int MINP;
                                 int MAXP;
                                 MINP = ((MIN+WDEF)*POWER)-WDEF;
                                 MAXP = ((MAX+WDEF)*POWER)-WDEF;
                                 cout<<"Minimum damage with power strike:";
                                 cout<<MINP<<endl;
                                 cout<<"Maximum damage with power strike:";
                                 cout<<MAXP<<endl;   
                                 system ("PAUSE");
                                 int MINSB;
                                 int MAXSB;
                                 MINSB = ((MIN+WDEF)*SLASHB)-WDEF;
                                 MAXSB = ((MAX+WDEF)*SLASHB)-WDEF;    
                                 cout<<"Minimum damage with slash blast:";
                                 cout<<MINSB<<endl;
                                 cout<<"Maximum damage with slash blast:";
                                 cout<<MAXSB<<endl;
        
                                 system ("PAUSE");
                                 return 0;           
                        }
                                 else if ( WEAPON = OneHandedSword )
                        {
                                 MIN = ((((STR*0.9*SkillMastery*4) + DEX)/100 * WA)) -WDEF;
                                 MAX = ((((STR*4) + DEX)/100 * WA)) -WDEF;
        
                                 cout<<"Minimum damage (normal slash):";
                                 cout<<MIN<<endl;
                                 cout<<"Maximum damage (normal slash):";
                                 cout<<MAX<<endl;
        
                                 system ("PAUSE");
                                 int MINP;
                                 int MAXP;
                                 MINP = ((MIN+WDEF)*POWER)-WDEF;
                                 MAXP = ((MAX+WDEF)*POWER)-WDEF;
                                 cout<<"Minimum damage with power strike:";
                                 cout<<MINP<<endl;
                                 cout<<"Maximum damage with power strike:";
                                 cout<<MAXP<<endl;   
                                 system ("PAUSE");
                                 int MINSB;
                                 int MAXSB;
                                 MINSB = ((MIN+WDEF)*SLASHB)-WDEF;
                                 MAXSB = ((MAX+WDEF)*SLASHB)-WDEF;    
                                 cout<<"Minimum damage with slash blast:";
                                 cout<<MINSB<<endl;
                                 cout<<"Maximum damage with slash blast:";
                                 cout<<MAXSB<<endl;
        
                                 system ("PAUSE");
                                 return 0;     
                       }
                                 else if ( WEAPON = OneHandedMace )
                       {
                                 MIN = ((((STR*0.9*SkillMastery*3.6) + DEX)/100 * WA)) -WDEF;
                                 MAX = ((((STR*4.4) + DEX)/100 * WA)) -WDEF;
        
                                 cout<<"Minimum damage (normal slash):";
                                 cout<<MIN<<endl;
                                 cout<<"Maximum damage (normal slash):";
                                 cout<<MAX<<endl;
        
                                 system ("PAUSE");
                                 int MINP;
                                 int MAXP;
                                 MINP = ((MIN+WDEF)*POWER)-WDEF;
                                 MAXP = ((MAX+WDEF)*POWER)-WDEF;
                                 cout<<"Minimum damage with power strike:";
                                 cout<<MINP<<endl;
                                 cout<<"Maximum damage with power strike:";
                                 cout<<MAXP<<endl;   
                                 system ("PAUSE");
                                 int MINSB;
                                 int MAXSB;
                                 MINSB = ((MIN+WDEF)*SLASHB)-WDEF;
                                 MAXSB = ((MAX+WDEF)*SLASHB)-WDEF;    
                                 cout<<"Minimum damage with slash blast:";
                                 cout<<MINSB<<endl;
                                 cout<<"Maximum damage with slash blast:";
                                 cout<<MAXSB<<endl;
        
                                 system ("PAUSE");
                                 return 0;     
                                 }
                                 }
                                 }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Code:
     if ( JOB == Page )
    edit - you've never initialized Page. Fix your indentation too.
    Last edited by Dino; 02-02-2008 at 06:58 AM.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    You dearly need to learn to indent. That code is a mess, sorry.
    http://cpwiki.sf.net/User:Elysia/Indentation
    Should put you on the right track.
    Also up warnings to max and pay heed to them. Assigning within an if should be warned by some compilers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    Use spaces man! Your code is so squished together it's unpleasent to read.

    >> Assigning within an if should be warned by some compilers.
    Hmm, I don't know about anyone else, but I'm glad my compiler doesn't.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    You be unhappy it doesn't.
    If (x = y)
    Is a faulty if and is caught by some compilers.
    if (x == y)
    is correct and
    int x;
    if ( (x = y()) == false )
    Should also work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    That's true... I have accidently left out one of the = and ended up with an infinit loop.

    But it is nice for code like this:
    Code:
    if(!(handle = CreateHandle())) return FALSE;
    EDIT: right, you already said that. You'r right, I be unhappy.
    Last edited by Yarin; 02-02-2008 at 08:18 AM.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    I added all the extra '=', and now it just closes after I type in 'Page' and press enter. What? Lol.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, WEAPON is a float, which you read after asking for something that looks like a string, and then you compare the value [assuming you have changed your single equal to a double equal] with a uninitialized float value. That means that there's no telling when/if this is true or not...
    Code:
        float WEAPON;
    ...
                          cout<<"Type of weapon? (2hSword, 2hMace, 1hSword, 1hMace...)";
                          cin>>WEAPON;
                          if ( WEAPON = TwoHandedSword ) 
    ...
    You probably want to read a string, and compare it with some string constants.

    Aside from the points commented on above, I would say that you should consider using a function for your actual calculation, rather than copy'n'paste essentially the same piece of code 4 times over - the only bits that vary are the multipliers in the first two calculations - those should be parameters to the function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

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, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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