Thread: Looping help please...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Looping help please...

    Ok I am making a simple texed based rpg. I know I did a long way and didn't use some of the stuff I should have and please don't comment on that.


    The long code...


    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <cstdlib>
    #include <string.h>
    
    using namespace std;
    
    int P_health;
    int P_level;
    int P_attack;
    int P_def;
    int P_weapon;
    int P_magic;
    int P_race;
    int P_totaldamage;
    int P_dead;
    
    int E_health;
    int E_attack;
    int E_def;
    int E_magic;   
    int E_alreadyset;
    int E_totaldamage;
    int E_dead;
    
    int goagain;
    int mainmenu;
    int gamemenu;
    int show;
        
    int main()
    {    
        goagain=0;
        P_dead=0;
        E_dead=0;
        gamemenu=0;
        show=0;
        mainmenu=1;
        while(mainmenu==1)
        {
            mainmenu=0;
            show=0;
            cout<<"1. Create Player\n";
            cout<<"2. Test Battle\n";
            cin>>gamemenu;
            if(gamemenu==1)
            if(show==0)
            {
                show=1;
                cout<<"\n\n\nWhat do you want to be?";
                cout<<"\n\n\n1. Warrior";
                cout<<"\n2. Knight";
                cout<<"\n3. Sorcerer\n";
                cin>>P_race;
                cout<<"\n\n\nYou have choosen "<<P_race;
                getch();
                if(P_race==1)
                {
                    P_level=1;
                    P_health=50;
                    P_attack=6;
                    P_def=4;
                    P_weapon=1;
                    P_magic=0;
                }
                system("CLS");    
                mainmenu=1; 
            }
            if(gamemenu==2)
            if(show==0)
            {
                show=1;
                system("CLS");
                cout<<"Battle Begin!!!\n\n\n\n";
                
                if(E_alreadyset==0)
                {            
                    E_health=20;
                    E_attack=7;
                    E_def=2;
                    E_magic=0;
                    E_alreadyset=1;
                }
                
                P_totaldamage=(P_attack-E_def);
                E_totaldamage=(E_attack-P_def);    
                
                do                            //I want it to loop from here...
                {
                    cout<<"Your attack...\n\n\n\n";
                    getch();
                    E_health=E_health-(P_attack-E_def);
                    cout<<"You did "<<P_totaldamage<<" damage";
                    getch();           
                
                    cout<<"\n\n\n\n";
                
                    cout<<"Enemy's attack..\n\n\n\n";
                    getch();
                    P_health=P_health-(E_attack-P_def);
                    cout<<"The enemy did "<<E_totaldamage<<" damage to you";
                    getch();        
                
                    if(P_health<1)
                    {
                        P_dead=1;
                    }
                
                    if(E_health<1)
                    {
                        E_dead=1;
                    }        
                
                    if(E_dead=1)
                    {
                        system("CLS");
                        mainmenu=1;
                    }    
                
                    if(P_dead=1)
                    {
                        system("CLS");
                        mainmenu=1;
                    }   
                }while(E_dead==0);            //to here, this would be the end of the loop.
            }
            if(gamemenu==100)
            if(show==0)
            {
                show=1;
                cout<<P_health<<"\n"<<E_health;
                getch();
                system("CLS");
                mainmenu=1;
            }       
        }
        getch();
        return 0;
    }

  2. #2
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    What exactly is the problem you want solving?

    DT
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    well, there's a few of typos like this:

    >> if(E_dead=1)
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    It says in the code...

    do //I want it to loop from here...

    }while(E_dead==0); //to here, this would be the end of the loop.


    You just look, look ver hard in this case, LOL

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    what do you mean by typos? The program compiles and runs just fine (well not the loo[ing part yet).

  6. #6
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    ok cool. well, the loop is there in place but as Seb pointed out, you are assigning the enemy and the player as dead when you actually need a conditional ==

    Code:
                  if(E_dead=1)
                  ...   
                  if(P_dead=1)
                  ...
    That would stop the loop after one go round. You want:

    Code:
                  if(E_dead==1)
                  ...   
                  if(P_dead==1)
                  ...
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  7. #7
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    (a very easy and common typo)
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    omg thanks so much...let my try it out just in case.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Oh yah it worked!!!!!!

    Thanks so much!!!!

    I guess I am just used to useing 1 = when I made games with game maker.

  10. #10
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Ah, yes. It's just an easy mistake to make anyway, I do it all the time, tho less now.

    no probs, this site is great innit!
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Yup

  12. #12
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Congratulations on your code Runehunter - there a couple things some of the C++ coders would correct you on, however you seem to have come a long way in a short period of time. Good to have you on the board you'll find all the help you need here, in no time you'll be helping other n00bies.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  13. #13
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Helping other people...well I do a ton of helping every where. I think I am getting all helped out.

    And yes I know the people that know alot about c++ would have made this a completely nother way. I choose the had seemingly I know the way I am doing very well.

    But thanks every one again!

    Oh and is 14 a good age to learn C++?

    And is c++ a good first codeing lang.?

    Not to try and show off (wich I know I am not at all)

  14. #14
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I don't see why not as long as in intrests you earlier you start the better you will be. It just might get harder if you want to go into 3d programming though because of the math stuff but other than that i see no problem
    Woop?

  15. #15
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ok good. I suppose it is best to start eirly and then you can learn harder stuff when I grow up. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 06:03 AM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM