void store ()
{
string answer2;
cout << endl;
cout << location <<endl;
cout << "Now that you have acquired your party. You should bring supplies with you.\n"
<< "You only have $1000 to spend. So choose wisely." << endl << endl;
cout << "Choose which supply you would like to purchase" << endl;
cout << "1) Medical kit" << endl;
cout << "2) lighter" << endl;
cout << "3) knife" << endl;
cout << "4) food" <<endl;
cout << "5) weapons" << endl;
cout << "6) clothing" << endl;
cout << "7) rope" << endl;
cout << "8) tent" <<endl;
cout << "9) compass" << endl;
cout << "10) unknown" <<endl <<endl;
while (true)
{
if (cin >> answer2)
{
if (answer2 == "1")
{
cout << "A medical kit will heal your party's wounds. " <<endl <<endl;
break;
}
elseif (answer2 == "2")
{
cout << "A lighter will provide you with fire. "<<endl <<endl;
break;
}
elseif (answer2 == "3")
{
cout << "A knife will provide you will a valuable tool as well as a weapon. "<<endl <<endl;
break;
}
elseif (answer2 == "4")
{
cout << "Food is essential to surviving. "<<endl <<endl;
break;
}
elseif (answer2 == "5")
{
cout << "A weapon will provide you with strong protection. "<<endl <<endl;
break;
}
elseif (answer2 == "6")
{
cout << "Clothing will provide you protection from the weather. "<<endl <<endl;
break;
}
elseif (answer2 == "7")
{
cout << "Rope will provide you the ability to craft in the wilderness. "<<endl <<endl;
break;
}
elseif (answer2 == "8")
{
cout << "A tent will provide your party with shelter. "<<endl <<endl;
break;
}
elseif (answer2 == "9")
{
cout << "A compass will provide you with navigation. "<<endl <<endl;
break;
}
elseif (answer2 == "10")
{
cout << "undetermined."<<endl <<endl;
break;
}
else
{
cout << "That is not a correct answer, please try again."<<endl <<endl;
}
}
}
cout << "\t\t\t\t\t\tPress y and Enter to continue." <<endl;
while(true)
{
if(cin >> answer2)
{
if(answer2 == "y")
break;
}
}
}
This is a function inside my program that is pretty much a store. The user starts off with 1000 dollars and purchases reduce the money amount depending on what they buy,
im wondering if i can condense this whole function...its seems repeatative and i think there would be a way to use arrays to do that, but i cant figure out how to have different items at a store, and use arrays.
But then again i dont know if a store would just be that long either.
i only started working on the first option (medkit) so the rest of them are not done.
i also am having trouble with the process of using loops to return the user back to the store menu after choosing an option(whether they buy or not), and then breaking the loop after they are done
i have read through classes, but it just confused me. So i stuck with the basics till i learn them, before i decided to move to classes.
plus i am totally lost when i look at the code you posted lol
@metalburr:
By having two functions you can create a mutual recursion between them. One function calls the other which in turn calls the first.
Though you will need some way to get out of the shop!
This will work like this:
The main calls menu();
In Menu, you make a choice.
It calls the choice();
choice(); calls menu() again.
This pattern continues, until you put a way to leave the shop.