What did you write your code with? In which text editor? It might pay
to invest in a good one because they can help with neatness as it may
make your code easier to follow.
A few things you may like to try:
* Whenever you enter new level of scope, or open a {, indent your code
until you exit that level of scope, or until you close the code block with };
* Try spacing things out, so if you declare a group of variables, and then
start making function calls put some white space in between them. You
may also like to do this by relevance.
* You may also find it easier to read if you hand warp your code. Although
most text editors have word wrap functionality, not all do (this forum
being one)
some examples of this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
bool loop = true; /* Main loop control variable */
/*
* numbers
*/
int num01 = 1;
int num02 = 2;
int num03 = 3;
int num04 = 4;
/*
* a long string
*/
std::string str = "This is a really long string. \n" +
"However, instead of just writing it all out on one line" +
"I am word wrapping it by myself for ease of reading.\n" +
"I can do this because the line does not end until the compiler" +
" sees a \";\" character. Until then I can continue appending " +
"strings together to be assigned to my variable, str.\n\n" +
"P.S. Notice how I indented the subsequent lines a reasonable " +
"amount? Because I have done this I can easily see that I " +
"Have not ended the prvious line. My text editor helped alot.\n\n";
/* std::string str */
int main()
{
/*
* some variables
*/
int aNewInt = 0;
char aNewChar = 'a';
string aNewString = "aNewString";
float aNewFloat = 0f;
/*
* player stats
*/
int damage = 4;
int hp = 10;
int attack = 1;
/*
* enemy stats
*/
int enemy_dam = 2;
int enemy_hp = 15;
int enemy_att = 2;
while ( loop == true )
{
/*
* sending strings to stdout
*/
std::cout << str;
std::cout << "New string\n";
std::cout << "A more detailed string\n\n";
if (...)
{
...
} /* if (...) */
else
{
...
} /* if (...) else */
} /* while ( loop == true ) */
return 1;
} /*main() */
|
With your use of goto, If you changed the main label into a
while
loop, close it on line 169 and delete your other
goto loops and it
should work in the same way. Because the
goto main statments
are the last line of every route of that switch, then if you instead leave
them, it will hit the
break statement and move to the end, which is
the end of an
if statement. As the rest of the code is in the
else that corresponds to the
if statement you will go strait to
the end of the while loop.
Try watching the flow of your code and you may discover that you will get
to where you want to go using a few more if statements. Perhaps in
different places.
One last thing
|
playerxp = playerxp -= 10;
|
that was on line 159 and I see you have done it in at least one other spot.
what you want to do is remove 10 from playerxp. To do that all you have to
do is
playerxp = playerxp - 10;
. The
-= operator makes
it easier to do by removing the right hand side from the variable on the left.
So, the following two lines of code are the same.
1 2
|
playerxp = playerxp - 10;
playerxp -= 10;
|
What you have done still works, but is essentially assigning -10 to the same
variable twice. Hope that helped a little. Sorry if I seemed a bit condescending.