Heya, I'm new to the forums and to C++ (4 days FTW) and I need some help with this code. It's basically a jumbled mess, but I follow its odds and ends to make sure it works, but I'm having problems with one code. If anyone can help, please help! ='(
Operating System: Windows 7
Warning, the following may hurt your eyes from organization.
Also, this is a segment of a longer code.
My Goal: after submitting Def, the program returns to int again = 0 on line 16.
Problems: after submitting Def, the program ends.
Seriously, next time pls use the code tag to post ur code..
and as xander said, i think you just need to use the while loop in the program.. refer to the tutorial given above..
Because you've admitted to being new I won't get on your case about using objects for this kind of stuff, but seriously do the entire tutorial on this site and pay extra attention in the "classes" section of it. This will be time VERY well spent.
That being said, stuff like this is why I encourage people to go Old-School-Geek and read up on a few Pencil Paper RPG's, it avoids nasty looking combat systems like this. You have the user entering way more variables then in necessary, "HP" "damage" and "pain" should all be functions of your "Def" variable, and you don't even need all of them. Simularly, "attack" should come from "Str". By automating stuff like this you spend less time on set up and more time on playing the game.
Hey, thanks for the tips, like I said that was just a segment of the whole program, and sorry about not using the codes, like I said, I'm new. As for the game I have (had), thank you very much to Xander314 because the while loop works, but I still have 1 problem. At the very end of my code is a
1 2 3 4 5 6
cout<<"Do you want to play again?";
cin>>PlayAgain;
if (PlayAgain = "yes")
again = 1;
elsereturn 0;
This is where I mainly need that again system to work.
Line 3 is your problem, a single '=' character means assignment. You want to use a double "==" character for comparison. In both cases do not use the quotes.
fixed it, Computergeek01, but it won't go back to the start. It seems to overlook again = 1. Is there a specific directive I need (if that's what you call them)?
Or am I doing something wrong with my int again=0; line?
Yeah, I used a while loop on the statistics, but can I while loop something inside a do loop? Like, I have a do/while loop for my combat sequences. So, can I make a while loop that long, and into a do function, without effecting anything to drastically?
I got the again line from some guy on Yahoo answers, and it doesn't have to be again, it can be any word as long as you go int (variable) = (number);
Although, yahoo answers isn't that trustworthy.
Anyways, the current state is I need to get you to restart the program without having to reenter your name, and I don't think the While loop will work ='(
The code in your original post. Is that a segment of code from the whole program? I don't understand exactly what you are trying to achieve but from what I speculate is that you want your program to jump from the end to the beginning (or near the beginning). There is no jump statements in C++ so the best way to iterate again until the user does not input "yes" would be using a while loop.
@ OP: This is called an "Embedded Loop" and is really easy in C++, there's no magic trick to it:
1 2 3 4 5 6 7 8
while(/*These Parameters Are True*/) /*Start First While Loop*/
{
while(/*These Other Parameters Are True*/) /*Start Second While Loop*/
{
/*Run This Code*/
} /*End Of Second While Loop*/
} /*End Of First While Loop*/