-
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;
}
-
What exactly is the problem you want solving?
DT
-
well, there's a few of typos like this:
>> if(E_dead=1)
-
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
-
what do you mean by typos? The program compiles and runs just fine (well not the loo[ing part yet).
-
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)
...
-
(a very easy and common typo)
-
omg thanks so much...let my try it out just in case.
-
Oh yah it worked!!!!!!
Thanks so much!!!!
I guess I am just used to useing 1 = when I made games with game maker.
-
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!
-
-
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. :p
-
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)
-
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
-
Ok good. I suppose it is best to start eirly and then you can learn harder stuff when I grow up. Thanks.