#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
goto test2;
string action_string;
string deci_string;
string shop_string;
int hp;
int maxhp;
int mhp;
int att;
int matt;
int currexp;
int expg;
int lv;
int z;
int gold;
int potion;
int herb;
int weapon;
potion = 0;
gold = 25;
z = 0;
maxhp = 100;
hp = 100;
mhp = mhp + 3 + matt * 2;
att = att + lv * 5;
matt = matt + mhp / 3;
currexp = currexp + expg;
lv = 1;
cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+";
cout << "\n";
cout << "+ Dragon Hunter +";
cout << "\n";
cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+";
cout << "\n\n\n\n";
cout << "Controls:\n-Type the commands on the side. Case is imporatant.";
cout << "\n-You gain a level when your experience is full. Level ups give \n you more health, and attack power. \n-Gold is used to by new equipment and sleep at the inn.";
cout << "\nType OK to continue.";
cout << "\n";
z = z + 1;
while (z = 1)
{
cin >> deci_string;
if (deci_string == "OK")
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYour adventure starts in the town of Ravenhome. \nYou're a young man, whos destiny is woven into the fabric of time.\n";
if (z = 2)
{
ravenhome;
cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
cout << " " << endl;
cout << "You are in the town square of Ravenhome. Here are your options: " << endl;
cout << "Hunt - Traverse the fields, to find monsters." << endl;
cout << "Shop - Enter the market to buy equipment." << endl;
cout << "Travel - Travel to a different town." << endl;
cout << "Stats - Check statistics." << endl;
cout << " " << endl;
cout << "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" << endl;
cout << " " << endl;
cout << "Which do you choose? \n";
cin >> action_string;
if (action_string == "Stats"){
cout << "You're Health is ";
cout << hp;
cout << " out of ";
cout << maxhp;
cout << ".\n";
cout << "You have ";
cout << gold;
cout << " Gold.\n";
cout << "You're inventory contains:\n";
cout << potion;
cout << " Potions";
cout << z;
}
if (action_string == "Shop")
{
test2;
cout << "Here is a list of items you may purchase\n\n";
cout << " Items \n" ;
cout << "------------------\n" ;
cout << "-Potion, Ten Gold.\n\n" ;
cout << " Weapons \n" ;
cout << "------------------\n" ;
cout << "-Dagger, Twenty Five Gold\n" ;
cout << "-Baselard, One Hundred Fifty Gold\n";
cin >> shop_string;
if (shop_string == "Potion") {
if (gold >= 10){
potion = potion + 1;
gold = gold - 10;
cout << "That will be Ten Gold";
goto shop;
}
else {
cout << "You don't have enough Gold";
}
}
if (shop_string == "Dagger") {
if (lv >= 2) {
weapon = 1;
gold = gold - 25;
}
else {
cout << "You need to be a higher level\n" ;
}
if (shop_string == "Baselard") {
if (lv >= 4) {
weapon = 2;
gold = gold - 150;
}
else {
cout << "You need to be a higher level\n" ;
}
if (shop_string == "Leave") {
goto ravenhome;
}
}
}
}
}
}
else {
cout << "Unknown Command: ";
cout << action_string;
cout << "\nTry again.\n";
cin >> action_string;
}
}
cin.get();
return 0;
}
For some odd reason, I can't get the goto function to work at all.
I've even just c&p'd a tutorial off the internet, and it doesn't work.
It says that they're all unidentified.
You shouldn't be using goto statements. Though there are very rare cases where they can be used usefully, they should generally be avoided. There is usually going to be a much better way. And the gotos are very poorly laid out in this program.
Though I will tell you the compiler is complaining because when you are making the label, the statement is finished with a colon (:) and not a semi-colon (;).
This apparent "tutorial" should really be an example of how not to program, as opposed to a useful tool for learning. Aside from the syntax errors, the very first line in the entry point of the program calls a goto before initializing any variables, variables that are used in the code that was skipped to.
Ah. Well, I just threw that in there to test it. I was wanting to skip all the variables.
Thank you for clearing that up. It's odd, because all the tutorials I found online, use ;, not :.
Well, I suppose I better start re-writing things then....