   Concerning My Barebones RPG And levelling system
  While it may not seem like it this program is the brainchild of an extensive 6 hour programming bender. I do not pride myself on programming but wish avidly to improve.My problems are:The program runs, but not as intended.  -The program immediately levels the player to 2, before even running the monbattle() function, which leads me to believe there is something wrong with the "while (xp<xpneeded)" loop. Therefore I speculate that either the xp or xpneeded variable is faulty.I really believe the program will run as intended with a few minor fixes. May I have some assistance? Here is the code:#include <stdio.h>//Declaring variables globally because this is the easiest way to do it for meint a;int monhp=25;int xp;int lvl=1;int xpneeded;//monbattle function, designed to initiate a single battle and give 10 xp.void monbattle(){while (monhp >0){printf ("The monsters hp is %d!\n",monhp);printf ("How much do you want to attack for?\n");scanf ("%d",&a);monhp-=a;printf("The kobold's hp is now %d\n",monhp);}printf("You have slain the Kobold! You gain 10 xp!\n");xp+=10;printf ("You now have %d xp!\n",xp);monhp+=25;}//monbattlestop//lvlscr function, designed to print a level if the player//reaches a certain amount of xp.    void lvlscr(){printf("You have levelled to %d!\n",lvl+1);lvl++;monbattle();}//lvlscrstop//engine, designed to check the users xp, and initiate the monbattle//function if players xp is below required level xp.//If it is above, initiate lvlscr function.void engine(){xpneeded==lvl*50;while(lvl<10){while(xp<xpneeded){monbattle();}lvlscr();xp=0;}}//enginestopmain (){engine();//scanf's, so the program doesnt automatically close.scanf("%d",&a);}Also, be gentle. Please take time to explain thoroughly because I cannot read your code naturally yet. It is still jarring on my eyes. Thank you!   
  Put breakpointstep through codefind problemJust watch the value of player level as you step through-me   ;  Paladine, I wholeheartedly want to get something out of the way. If I make a post on this forum, it's because I've already tried my butt off, and looked up on the issue. Then, and only then, I post on this forum. Thank you for your advice, though.Also, watching the player's level has been one of the main tools I have used. I have actually tried several things, and the players level is always the culprit. I can't get it to level smoothly.   ;  What happens if you initialize your variables to 0 in the beginning?   ;  Absolutely nothing changes.I changed the code a little bit. I moved the xpneeded definition into the global variable when I initialized it. I also set xpneeded=lvl * 50 instead of xpneeded==lvl*50.#include <stdio.h>int a=0;int monhp=25;int xp=0;int lvl=1;int xpneeded=lvl * 50;//monbattlevoid monbattle(){while (monhp >0){printf ("The monsters hp is %d!\n",monhp);printf ("How much do you want to attack for?\n");printf ("Your xp is %d, your lvl is %d, and your xpneeded is %d.\n",xp,lvl,xpneeded);scanf ("%d",&a);monhp-=a;printf("The kobold's hp is now %d\n",monhp);}printf("You have slain the Kobold! You gain 10 xp!\n");xp+=10;printf ("You now have %d xp!\n",xp);monhp+=25;}//monbattlestop//lvlscrvoid lvlscr(){printf("You have levelled to %d!\n",lvl+1);lvl++;monbattle();}//lvlscrstop//enginevoid engine(){while(lvl<10){while(xp<xpneeded){monbattle();}lvlscr();xp=0;}}//enginestopmain (){engine();scanf("%d",&a);};  I think the problem is in here:void engine(){xpneeded==lvl*50;  // <---------one too many = perhaps?while(lvl<10){while(xp<xpneeded){monbattle();}lvlscr();xp=0;}BLAST, slightly too slow, good on you to catch it though, all my elusive bugs so far have been mixing up == and = .   ;  Yes sir, I did fix that. That was a problem. Now my code runs smoothly except for this: When I level, the xpneeded formula should equal 100 (lvl * 50), but it still equals 50. I know this because I have it print it out every time I do the monster battle now. See here:#include <stdio.h>int a=0;int monhp=25;int xp=0;int lvl=1;int xpneeded=lvl * 50;//monbattlevoid monbattle(){while (monhp >0){printf ("The monsters hp is %d!\n",monhp);printf ("How much do you want to attack for?\n");//Prints out the information each battle for diagnostic purposesprintf ("Your xp is %d, your lvl is %d, and your xpneeded is %d.\n",xp,lvl,xpneeded);scanf ("%d",&a);monhp-=a;printf("The kobold's hp is now %d\n",monhp);}printf("You have slain the Kobold! You gain 10 xp!\n");xp+=10;printf ("You now have %d xp!\n",xp);monhp+=25;}//monbattlestop//lvlscrvoid lvlscr(){printf("You have levelled to %d!\n",lvl+1);lvl++;monbattle();}//lvlscrstop//enginevoid engine(){while(lvl<10){while(xp<xpneeded){monbattle();}lvlscr();xp=0;}}//enginestopmain (){engine();scanf("%d",&a);}I am confused as to why it is doing this! It prints the lvl out as 2, and the xpneeded formula is xpneeded=lvl * 50, yet the xpneeded is still 50.. I'll continue investigating.   ;Quote:Original post by Mr_DerekAbsolutely nothing changes.I changed the code a little bit. I moved the xpneeded definition into the global variable when I initialized it. I also set xpneeded=lvl * 50 instead of xpneeded==lvl*50.*** Source Snippet Removed ***Problem then becomes the variable xpneeded never changes, right?  You'll need to add an update to that global variable in the lvlscr() function, just anotherxpneeded = lvl*50;after you increment the lvl variable.   ;  I know caps are frowned upon, but THANK YOU! I almost put two exclamation points.What is the reasoning behind doing this , though? I'd like to fully understand it.   ;  You initialize the variable as a global variable when the program first runs.  The problem before you added that line to the lvlscr() function was that the program will never run over that assignment operation again.  As it steps through the code, it assigns it the first time (as it passes through the globals at the top of your code) and never reads that portion of the code again.  Think about this: The code wants to run main(), so you design all the other functions so that they will be called somehow (either directly or within each other) from within main().  By defining variables outside main(), you tell the compiler that these variables exist, but you still need to *do* things with them somewhere in main().  Until you added that update in the lvlscr() function, xpneeded was never updated from within main().   