help

This is a discussion on help within the C++ Programming forums, part of the General Programming Boards category; This dumb fighting system. It seems like I'm going in circles. I have the same problem I started with, but ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    help

    This dumb fighting system. It seems like I'm going in circles. I have the same problem I started with, but now for a different reason. If I come back to fight the man again it says hes already dead. Occasionally his hp will start at something like 35 or some wierd number.

    Code:
    	case 'f':
    	do{
    	    cout<<"1-man\n";
    	    cout<<"2-goblin\n";
    	    cin>>monster;
    	    if(monster=='1'){
    	       cout<<"You encounter a man";	
    	       finalcom=20;
    	}
    	}while(monster<1 || monster>4);
    	while(finalcom>0){              //fight
    	    fight=rand()%5+1;
    	    cout<<"How are you going to combat you opponent?";
    	    cin>>combat;
    	    if(combat=='a'){                //attack
    	       fcom=(((strength*3)+agility)/fight);
    	       finalcom=mhp1-fcom;
    	       mhp1=finalcom;
    	}
    	if(finalcom>0){
    	    cout<<"His hp is"<<finalcom<<"\n";
    	}
    	}
    	cout<<"\nHe is dead\n";                    //death

    How do you edit the variables in a structure? If this is how you do it then why won't it cout?
    Code:
    	bsword brsword;
    	brsword.bsi=1;
    	if (brsword.bsi=='1'){
    	cout<<"Bronze Sword\n";
    	}

    Please help
    My computer is awesome.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    You're probably not re-initializing the health values.

    Also:
    Code:
    brsword.bsi=1;
    	if (brsword.bsi=='1'){
    	cout<<"Bronze Sword\n";
    	}
    You are comparing it to the ASCII value of 1, not the numerical value of 1. If you want to compare it to the NUMBER 1, just type 1 and not '1'

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    You're probably not re-initializing the health values.
    How do I re-initialize them if I'm not already?
    My computer is awesome.

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    Just make sure you're actually setting the variable at some point.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Code:
    	    if(monster=='1'){
    	       cout<<"You encounter a man";	
    	       finalcom=20;
    	}
    That is where I re-initialize it.
    My computer is awesome.

Popular pages Recent additions subscribe to a feed

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