{
//The Error!?
int choice = 0;
while(choice != 8)
{
cout << "----LOCATIONS----" << endl;
cout << "(please select one of the below locations to learn more)\n" << endl;
cout << "1: Nunga" << endl;
cout << "2: Tiagor" << endl;
cout << "3: Alhari Desert" << endl;
cout << "4: Estess" << endl;
cout << "5: Yovania" << endl;
cout << "6: The Great Ocean" << endl;
cout << "7: The frozen wastes" << endl;
cout << "8: Read some history(from history you can return to main)\n" << endl;
cin >> choice;
cout << endl;
switch (choice)
case 1:
{
cout << "----NUNGA----" << endl;
cout << "Nunga is a country in the South-West of the eastern hemisphere" << endl;
cout << "of Mystice. It is one of the few countries that didn't\n succumb to the darkness of Yovania(see Locations #5: Yovania)." << endl;
cout << "Nunga is one of the superpowers of Mystice.\n The country is mainly affiliated with the element Earth & the goddess Terra." <<endl;
cout << "Several great people have come from Nunga, mainly White Wizards." << endl;
cout << "Xhalite & Zyaji Dirkrest were both from Nunga. Kathruia Ahenin was from Nunga as well." << endl;
cout << "(for more information on these people, go to history->famous/infamous historical figures)" << endl;
cout << "Nunga has a very well organized and powerful military.\n Demonstrated by that fact that it beats back Yovanian forces each time!" << endl;
cout << "The country is so named for its native magical creature called a nungun" << endl;
cout << "Nunga was founded thousands of years ago by Levonian men.\n Levonia is now the dark realm of Yovania.\nLearn more in history section." << endl;
cout << "The capitol city is Port Serene at the very North-end of the Bay of Life" << endl;
break;
}
case 2:
{
cout << "----TIAGOR----" << endl;
cout << "An island chain of mystical power...\n filled with water elemental energy." << endl;
cout << "Located North of Nunga & East of the Alhari Desert. Home to the white wizard Kino'oh." << endl;
cout << "It takes up the entire North-Eastern seaboard\n of the western continent above Nunga," << endl;
cout << "plus the huge chain of islands extends far East into the Great Ocean" << endl;
cout << "with dagger & tearing claw islands at the top near the Artic Waste & the Whirling Seas." << endl;
break;
}
As you can see I am writing a guide to a fantasy world. Please help thank you!
That error happens when you declare variables inside of switch cases, as it's possible to not fall into that case and then hit the end of the block, destructing the variable that wasn't even constructed.
int choice;
{
//No Error?
choice = 0;
while(choice != 8)
{
cout << "----LOCATIONS----" << endl;
cout << "(please select one of the below locations to learn more)\n" << endl;
cout << "1: Nunga" << endl;
cout << "2: Tiagor" << endl;
cout << "3: Alhari Desert" << endl;
cout << "4: Estess" << endl;
cout << "5: Yovania" << endl;
cout << "6: The Great Ocean" << endl;
cout << "7: The frozen wastes" << endl;
cout << "8: Read some history(from history you can return to main)\n" << endl;
cin >> choice;
cout << endl;
switch (choice)
case 1:
{
cout << "----NUNGA----" << endl;
cout << "Nunga is a country in the South-West of the eastern hemisphere" << endl;
cout << "of Mystice. It is one of the few countries that didn't\n succumb to the darkness of Yovania(see Locations #5: Yovania)." << endl;
cout << "Nunga is one of the superpowers of Mystice.\n The country is mainly affiliated with the element Earth & the goddess Terra." <<endl;
cout << "Several great people have come from Nunga, mainly White Wizards." << endl;
cout << "Xhalite & Zyaji Dirkrest were both from Nunga. Kathruia Ahenin was from Nunga as well." << endl;
cout << "(for more information on these people, go to history->famous/infamous historical figures)" << endl;
cout << "Nunga has a very well organized and powerful military.\n Demonstrated by that fact that it beats back Yovanian forces each time!" << endl;
cout << "The country is so named for its native magical creature called a nungun" << endl;
cout << "Nunga was founded thousands of years ago by Levonian men.\n Levonia is now the dark realm of Yovania.\nLearn more in history section." << endl;
cout << "The capitol city is Port Serene at the very North-end of the Bay of Life" << endl;
break;
}
case 2:
{
cout << "----TIAGOR----" << endl;
cout << "An island chain of mystical power...\n filled with water elemental energy." << endl;
cout << "Located North of Nunga & East of the Alhari Desert. Home to the white wizard Kino'oh." << endl;
cout << "It takes up the entire North-Eastern seaboard\n of the western continent above Nunga," << endl;
cout << "plus the huge chain of islands extends far East into the Great Ocean" << endl;
cout << "with dagger & tearing claw islands at the top near the Artic Waste & the Whirling Seas." << endl;
break;
}
Then there is another before it with the same type of switch statement. The only thing different is the displayed information. In fact my whole program is a huge switch statement with other switch statements within making sub sections of the guide to the land of Mystice.
Line 23~50. But that's why you should put it in a function ;) If you need to go back to the main loop, you can just return from the function and have a loop around the entire int choice stuff.
#include<iostream>
usingnamespace std;
int main()
{
int choice = 0;
while(choice != 8)
{
cout << "----LOCATIONS----" << endl;
cout << "(please select one of the below locations to learn more)\n" << endl;
cout << "1: Nunga" << endl;
cout << "2: Tiagor" << endl;
cout << "3: Alhari Desert" << endl;
cout << "4: Estess" << endl;
cout << "5: Yovania" << endl;
cout << "6: The Great Ocean" << endl;
cout << "7: The frozen wastes" << endl;
cout << "8: Read some history(from history you can return to main)\n" << endl;
cin >> choice;
cout << endl;
switch (choice)
{ //modify here
case 1:
{
cout << "----NUNGA----" << endl;
cout << "Nunga is a country in the South-West of the eastern hemisphere" << endl;
cout << "of Mystice. It is one of the few countries that didn't\n succumb to the darkness of Yovania(see Locations #5: Yovania)." << endl;
cout << "Nunga is one of the superpowers of Mystice.\n The country is mainly affiliated with the element Earth & the goddess Terra." <<endl;
cout << "Several great people have come from Nunga, mainly White Wizards." << endl;
cout << "Xhalite & Zyaji Dirkrest were both from Nunga. Kathruia Ahenin was from Nunga as well." << endl;
cout << "(for more information on these people, go to history->famous/infamous historical figures)" << endl;
cout << "Nunga has a very well organized and powerful military.\n Demonstrated by that fact that it beats back Yovanian forces each time!" << endl;
cout << "The country is so named for its native magical creature called a nungun" << endl;
cout << "Nunga was founded thousands of years ago by Levonian men.\n Levonia is now the dark realm of Yovania.\nLearn more in history section." << endl;
cout << "The capitol city is Port Serene at the very North-end of the Bay of Life" << endl;
break;
}
case 2:
{
cout << "----TIAGOR----" << endl;
cout << "An island chain of mystical power...\n filled with water elemental energy." << endl;
cout << "Located North of Nunga & East of the Alhari Desert. Home to the white wizard Kino'oh." << endl;
cout << "It takes up the entire North-Eastern seaboard\n of the western continent above Nunga," << endl;
cout << "plus the huge chain of islands extends far East into the Great Ocean" << endl;
cout << "with dagger & tearing claw islands at the top near the Artic Waste & the Whirling Seas." << endl;
break;
}
} //modify here
} //modify here
return 0;
}
@firedraco well I have a friend to help me since he makes up some of this stuff as well. This console application is really only meant as documentation for a bigger harder 3D game project my friends and I are working on. Yeah I guess I made up some of this lore.
dammit! I can't reply with my entire source code because it is too long and I know that would help me and you in figuring this out. I added the brackets and just got more confused not being able to find which brackets are which and then I can't compile with error: expected unqualified id before return.BUT I NEED THAT BRACKET TO TIE EVERYTHING TOGETHER SINCE IT IS THE int main() bracket!
Okay I put it in functions like firedraco suggested. It compiles and runs but is now buggier than ever and doesn't loop back to main options but instead closes when I press the integer for return to main and gives me this warning several times: statement has no effect.
So, what do I do now to get it back to what it was doing before this whole mess started??
I have an idea as to how to fix this buggy mess of a program. I figured that I could call a function to loop it back to the main options rather than a while loop?? Any idea what to do?