cout << "There are only " << new_pile2 << " left. Choose any number.\n";
cin >> user_choose1;
if (1 <= user_choose1 && user_choose1 <= new_pile2)
{
int computer_choose1 = 1 + rand() % ((choose_pile) - 1 + 1);
int new_pile = new_pile2 - (user_choose1 + computer_choose1);
int new_pile1 = new_pile2 - user_choose1;
if (new_pile1 == 0)
{
cout << "You Lose!\n";
initial_pile = new_pile1;
}
else
{
cout << "Thus, there are " << new_pile << " marbles left.\n";
initial_pile = new_pile;
if (1 <= computer_choose1 && computer_choose1 <= choose_pile)
{
if (new_pile == 0)
cout << "You Win!\n";
}
}
}
else
{
cout << "ERROR: Please choose a number again.\n";
}
Here is my code and I want to repeat the loop from "int new_pile2 = initial_pile - computer_choose1;" if the program gets to "cout << "ERROR: Please choose a number again.\n";"
What kind of operator do I need to use in order to make it repeat at a certain starting point?
There are many ways. You can create functions which perform the specific functions and just recursively call them. But I hear it is evil (as in dangerous code)...
You could use goto but as Kyon pointed out, it's also evil code.
A better option would be using loops. You could:
@Zia Ur Rehman: There is nothing wrong with functions recursivley calling themselves as far as virus signitures go. It's just hard for some of the new and mid level people to read\understand. In this particular case though the entire structure of the program would need to be overhauled to get it to work as it is supposed to (neat and efficent), I know this because I just tried to type up an example and my head started to hurt :p.