Thread: Whats my problem here?

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    35

    Whats my problem here?

    I cant figure out what im doing wrong here

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    struct User
    {
           int UHP; // Users Current Hit Points
           int max_UHP; // Users Maximum Hit Points
    };
    struct Challenger
    {
           int CHP; // Challengers Hit Points
           int max_CHP; // Challengers Maximum Hit Points
    };
    int main()
    {
        int Command;
        
        User Player;
        Challenger Enemy;
        
        Player.max_UHP = 100;
        Player.UHP = 100;
        Enemy.max_CHP = 100;
        Enemy.CHP = 100;
        int UATK = rand()%10; // Users Attack points
        int CATK = rand()%10; // Challengers Attack points
    
        cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
        cout<<"He then challenges you to a fight and you humbly accept.\n";
        cout<<"You can Attack.\n";
        cin>> Command;
        if ( Command == "AttacK" || Command == "attack" ) { Enemy.CHP - UATK;
        cout<<"You took out ">> UATK <<" points.\n"; }
        cin.get();
    }

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    35
    ok i fixed most of it but theres still something wrong with it and i have no idea why

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    
    string Command;
    
    struct User
    {
           int UHP; // Users Current Hit Points
           int max_UHP; // Users Maximum Hit Points
    };
    struct Challenger
    {
           int CHP; // Challengers Hit Points
           int max_CHP; // Challengers Maximum Hit Points
    };
    int main()
    {
        User Player;
        Challenger Enemy;
        
        Player.max_UHP = 100;
        Player.UHP = 100;
        Enemy.max_CHP = 100;
        Enemy.CHP = 100;
        int UATK = rand()%10; // Users Attack points
        int CATK = rand()%10; // Challengers Attack points
    
        cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
        cout<<"He then challenges you to a fight and you humbly accept.\n";
        cout<<"You can Attack.\n";
        cin>> Command;
        if ( Command == "AttacK" || Command == "attack" ) { Enemy.CHP - UATK;
        cout<<"You took out ">> UATK <<" points.\n"; }
        cin.get();
    }

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    32
    Could you be more specific on what exactly we are looking for?

    Compile wise

    Code:
        cout<<"You took out ">> UATK <<" points.\n"; }
    should be
    Code:
        cout<<"You took out "<< UATK <<" points.\n"; }

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    35
    this is the error i get

    no match for 'operator>>' in 'std:perators<< [with_traits=std::char_traits<char>

    i dont know its says its something wrong with this line

    cout<<"You took out ">> UATK <<" points.\n"; }

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    32
    Re read my post =)

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    35
    ohhhhhhhh i didmt even realize thats what i did sorry thanks

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    35
    ok im just not having a good day

    i fixed that which is a mistake i shouldnt of made but now instead of saying the final cout and telling me how much damage it did make it just ends the program

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    35
    ok nevermind i forgot to type in get.ignore(); after my input sorry about this, having a rough couple of days and cant think straight

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    32
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <string>
    
    using namespace std;
    
    string Command;
    
    struct User
    {
    	int UHP; // Users Current Hit Points
    	int max_UHP; // Users Maximum Hit Points
    };
    struct Challenger
    {
    	int CHP; // Challengers Hit Points
    	int max_CHP; // Challengers Maximum Hit Points
    };
    int main()
    {
    	User Player;
    	Challenger Enemy;
    
    	Player.max_UHP = 100;
    	Player.UHP = 100;
    	Enemy.max_CHP = 100;
    	Enemy.CHP = 100;
    	int UATK = rand()%10; // Users Attack points
    	int CATK = rand()%10; // Challengers Attack points
    
    	cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
    	cout<<"He then challenges you to a fight and you humbly accept.\n";
    	cout<<"You can Attack.\n";
    	cin>> Command;
    	cin.ignore();
    	if ( Command == "AttacK" || Command == "attack" )
    	{ 
    		Enemy.CHP - UATK;
    		cout<<"You took out "<< UATK <<" points.\n"; 
    	}
    	cin.get();
    }
    notice

    Code:
    	cin>> Command;
    	cin.ignore();
    Your program is ending right away because cin.get() waits for a return \n (when you hit enter). The problem is its keeping the enter in queue after you enter the word attack. so after you get the input, you put cin.ignore() which will ignore the next return. Try this and it will work for you.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    35
    my random number generators arent exactly coming up random ive gotten one everytime ive done it

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    32
    I knew you were going to ask that.

    The rand function is dependent on a random "seed" which to make it simple, dictates how the numbers are generated.

    add the following to your code.

    Code:
    //Includes
    #include <time.h>
    
    ........
    
    int main()
    {
        srand( time(NULL) );
    ....
    return 0;
    }
    just add those two lines and your numbers will be much m roe random. This will seed the random number generator with the current time and make your numbers appear much more random.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    35
    alright thanks yeah i had to use that in my death clock

  13. #13
    Registered User
    Join Date
    May 2006
    Posts
    35
    im sorry about this , I just cant get anything to particapte with me. Its not taking out the points from the hit points like its supposed to so even after the attack its still 100

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <time.h>
    
    
    using namespace std;
    
    string Command;
    
    struct User
    {
           int UHP; // Users Current Hit Points
           int max_UHP; // Users Maximum Hit Points
    };
    struct Challenger
    {
           int CHP; // Challengers Hit Points
           int max_CHP; // Challengers Maximum Hit Points
    };
    int main()
    {
        srand( time(NULL) );
        User Player;
        Challenger Enemy;
        
        Player.max_UHP = 100;
        Player.UHP = 100;
        Enemy.max_CHP = 100;
        Enemy.CHP = 100;
        int UATK = rand()%10; // Users Attack points
        int CATK = rand()%10; // Challengers Attack points
    
        cout<<"As your walking down a path a cloaked swordsman ambushes you.\n";
        cout<<"He then challenges you to a fight and you humbly accept.\n";
        cout<<"You can Attack.\n";
        cin>> Command;
        cin.ignore();
        if ( Command == "Attack" || Command == "attack" ) { Enemy.max_CHP-UATK;
        cout<<"You took out "<< UATK <<" hp.\n"; }
        cout<<"The challenger has "<< Enemy.CHP <<" hp left.\n";
        cin.get();
    }

  14. #14
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Code:
    if ( Command == "Attack" || Command == "attack" ) { Enemy.CHP-=UATK;

  15. #15
    Registered User
    Join Date
    May 2006
    Posts
    35
    its still doing the same thing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM