Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Best way to break?

Name: Anonymous 2009-02-01 12:26

my current hierarchy looks like this:

main()
{
for()
{
function();
}
}

function()
{
if
{
break;
}
}

apparently c++ doesn't like it if I have the function try and break the for loop, but i need that function to do so. What would be the proper course of action for this scenario?

Name: Anonymous 2009-02-01 13:00

Here's the source. I want the program to find combinations of ages for 3 people where the product equals 36. So I set the ages equal to 1 and made a nest of 3 loops. As I have it now, the program goes to the middle loop and iterates 1-36. At that point, I need it to reset the age to one and break into the 2nd loop so that it can iterate to 2, before going back into the inner loop and iterating to 36 again, etc. until all possible combinations are considered.



#include<iostream>
using namespace std;

void print(int w, int x, int y, int z);
void condition(int m, int n);

int main()
{
    int a=1, b=1, c=1, d=36;
   
    cout << "Possible ages for sons:" << endl << endl;
   
    for (a;a<=d;a++)
    {
        print(a,b,c,d);
        condition(a,d);
       
        for (b;b<=d;b++)
        {
            print(a,b,c,d);  
            condition(b,d);
           
            for (c;c<=d;c++)
            {
                print(a,b,c,d);
                condition(c,d);
            }
        }
    }
    system("pause");
    return 0;
}

void print (int w, int x, int y, int z)
{
     if (w*x*y == z)
     {
               cout << "son 1: " << w << endl << "son 2: " << x << endl << "son 3: " << y << endl << "-------------" << endl;
     }
}

void condition(int m, int n)
{
     if (m == n)
     {
           m=1;
           break;
     }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List