bool running = true;
while ( running ) // Get out your running shoes.
{
// Code here!
bool loop = true;
while ( loop )
{
// Here we ask if they want to keep going:
char choice; // Use a char.
// Options
std::cout << "Enter 1 to continue" << std::endl;
std::cout << "Enter 2 to quit" << std::endl;
std::cout << "Your choice? "; std::cin >> choice;
// Now we do some if statement checking
if (choice == '1')
loop = false; // Gets you out of the {} of the smaller while loop
elseif (choice == '2')
running = false, loop = false; // end both loops
else
std::cout << "\nI don't know what you wanted to do." << std::endl << std::endl;
// repeat smaller loop
}
}
Well I only gave you a snippet. If you still see it, its continuing the main loop then hits the mini loop again. Add some text above like a std::cout << "Main Loop" << std::endl;
You should be repeating the main loop everytime you press 1, and then it will ask if you want to do it again once the main loop is completed.
But i mean, when you press 1 --> it will make the triangle it is supposed to make. (not to continue the loop)
and when you press 2 --> is just stops the program
@ browni, thats not really working with my script :(
That's non standard. Never use void main(). You should probably ditch whatever tutorial you're using, because if it's using void main() who knows what other bad/non standard practices it's teaching you as well.
int main()
{
bool running = true;
while ( running ) // Get out your running shoes.
{
// Code here!
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
// Code
bool loop = true;
while ( loop )
{
// Here we ask if they want to keep going:
char choice; // Use a char.
// Options
std::cout << "Enter 1 to continue" << std::endl;
std::cout << "Enter 2 to quit" << std::endl;
std::cout << "Your choice? "; std::cin >> choice;
// Now we do some if statement checking
if (choice == '1')
loop = false; // Gets you out of the {} of the smaller while loop
elseif (choice == '2')
running = false, loop = false; // end both loops
else
std::cout << "\nI don't know what you wanted to do." << std::endl << std::endl;
// repeat smaller loop
} // end of while (loop)
} // end of while (running)
// DO NOT CODE HERE UNLESS YOU ONLY WANT TO SEE THIS WHEN THE PROGRAM CLOSES.
return 0; // END
}