Recently I have been making a text-based game to imitate a game from the 90's for my friend, and it went all well, but the Yes/No didn't work because I had an if statement then another if statement following first, so then I change it to an if statement with an else statement following the if statement, but get error's like "else without previous if" and "label referenced but not defined" which is really weird because a few lines below the reference in the defined label... I really need help with this, because I tried googling it but comes up with useless Microsoft threads that don't relate whatsoever.
My Code:
#include <iostream>
int main() //main function
{
std::cout << "NOTE: when you see [Y/N], it is a choice option, please capitalize letter of choice!!\n";
lab1:
char name = NULL;
int age = NULL;
char ans1 = NULL;
char strong = NULL;
char ans2 = NULL;
char ans3 = NULL;
char smart = NULL;
char ans4 = NULL;
char ans5 = NULL;
std::cout << "Well hello! What is your name?\n";
std::cin >> name;
std::cout << "And your age is?\n";
std::cin >> age;
std::cout << "Ok so your name is " << name << " and you are " << age << "?\n";
std::cout << "Is that correct? [Y/N]\n";
std::cin >> ans1;
if (ans1 == 'Y');
{
std::cout << "Well then, lets get started with your main ability!\n";
goto lab2;
}
else
{
std::cout << "Oh sorry, my bad lets enter it again shall we?\n";
goto lab1;
}
lab2:
lab4:
lab6:
std::cout << "Strong? [Y/N]\n";
std::cin >> strong;
if (strong == 'Y');
{
std::cout << "Are you sure? Only ONE main ability can be chosen! [Y/N]\n";
std::cin >> ans2;
if (ans2 == 'Y')
{
goto lab3;
}
else
{
goto lab4;
}
}
else
{
std::cout << "Are you sure? Move to next ability? [Y/N]\n";
std::cin >> ans3;
if (ans3 == 'Y');
{
goto lab5;
}
else
{
goto lab6;
}
}
lab5:
lab8:
lab10:
std::cout << "Smart? [Y/N]\n";
std::cin >> smart;
if (smart == 'Y')
{
std::cout << "Are you sure? Only ONE main ability can be chosen! [Y/N]\n";
std::cin >> ans4;
if (ans4 == 'Y')
{
goto lab7;
}
else
{
goto lab8;
}
}
else
{
std::cout << "Are you sure? Move to next ability? [Y/N]\n";
std::cin >> ans5;
if (ans5 == 'Y')
{
goto lab9;
}
else
{
goto lab10;
}
}
lab9:
lab3:
lab7:
std::cout << "Done!";
}