my program that im supposed to write needs to divide 200 hrs of work between four workers , based on the following conditions:

if worker one works 2 days, then he must work for only 2 hrs each day, totatl hrs=4

if worker two works 4 days, then he must work for only 4 hrs each day, totatl hrs=16

if worker three works 6 days, then he must work for only 6 hrs each day, totatl hrs=36

if worker four works 12 days, then he must work for only 12 hrs each day, totatl hrs=144

total hours= 144+36+16+4=200 hours

therefore, if we divide 200 hours of work over four workers, their number of days worked squared equals the total hours they should work.

my question is, what would be the best way to write this program? using a 'for' loop or a do...while loop?

ive done it both ways, both not working.

can someone please take a look at it?

thanks!

Code:#include <iostream> #include <cmath> using namespace std; int main () { int a=0, b=0, c=0, d=0; //int counter; //counter= 1; //a==200-b-c-d && b==200-a-c-d && c==200-a-b-d && d==200-a-b-c do { 50= (a+b+c+d); //a=200-b-c-d; //b=200-a-c-d; //c=200-a-b-d; //d=200-a-b-c; if (sqrt(a)==static_cast<int>(sqrt(a))) cout<<a<<" "; if (sqrt(b)==static_cast<int>(sqrt(b))) cout<<b<<" "; if (sqrt(c)==static_cast<int>(sqrt(c))) cout<<c<<" "; if (sqrt(d)==static_cast<int>(sqrt(d))) cout<<d<<" "; //counter++; cout<<endl; } while (200/4== a+b+c+d); //a+b+c+d==200); return 0; }

the comments in this program are what i was originally using but made them comments to test if the program would work without them...

and using 'for' loop:

Code:#include <iostream> #include <cmath> using namespace std; int main () { int Employe=0; int total_hour=0; for(int i=1;i<=4;i++) { Employe=i; if(Employe==1) { total_hour+=((i+i)*(i+i)); //cout<<total_hour; } else if(Employe==2) { total_hour+=((i+i)*(i+i)); } else if(Employe==3) { total_hour+=((i+i)*(i+i)); } else if(Employe==4) { total_hour+=((i*3)*(i*3)); } } cout<<total_hour<<" "<<endl; return 0; }