I recently started learning c++, and I am just testing what I know by making a terrible little game.
I want to jump back in my code, so I learnt about a goto statment. Here is my code(not all of it, just the goto bit)
moving: if(moveChoice == "Forward"){ cout << "You moved Forward" << endl; moveChoice = ""; if(firstTargetRand == 2){ cout << "You encountered a tree!" << endl; }if(firstTargetRand != 2){ cout << "goto init" << endl; goto moving; } } Now "goto moving" is getting called ( checked with cout goto init ) but this isn't working. I know this is prob a really stupid mistake, but I can't see anything wrong with it
gotois working fine. Couldn't tell you where you're wrong though without knowing what you're doing.moveChoiceis of typechar*. Change it tostd::stringto fix the first problem. The second problem would be to un-learn thegoto;-)gotois just about the easiest way to get spaghetti code if not used correctly. This code is a prime candidate for a loop.goto, this article is a good place to start.