Hi I am trying to assign 5 people various objectives between day0 and day13. However the output is not correct and goes fuzzy in the second half of the output. This is my code:

for(int x=1, y=0; y < 5, x < 15; x++, y++)
  {
    array[x][y] = objectives[y];
    if (y == 4)
      {
      y = 0;
      continue;
      }
  }

What I am trying to do is go through the y array with the x array simultaneously, but when I reach the end of y (i.e. y==4) I want to reset y (i.e. y=0) but continue x from where it was previously (i.e. in the first case x=5 and y =0; y++,x++)

This is how I am printing out:

for(int y=0; y<5; y++)
  {
  for(int x=0; x<15; x++)
    {
    cout<<array[x][y];
    cout << '\t';
    }
  cout<<endl;
  }

Recommended Answers

All 4 Replies

Your for statement is set up wrong.

for(int x=1, y=0; y < 5, x < 15; x++, y++)

Are you sure you want your condition part of a comma operator?

Try running this code.

#include <iostream>

int main()
{

  for (int i = 0, j = 0; i < 5, j < 15; ++i, ++j)
  {
	std::cout << "i->" << i << " j->" << j << std::endl;
  }
  return 0;
}

I think I have fixed that part but the output is still messy and I think its because of the output code.
Fixed code:

int x=1, y=0;
while((y < 5) && (x < 15))
  {
    array[x][y] = duties[y];
    if (y == 4)
      {
      y = 0;
      continue;
      }
  y++;
  x++;
  }

As you can see, the first dishes to vacuum is fine but afterwards the output is glitchy?

output:

Sam	dishes					dishes					dishes					dishes			
Chinky		toilet					toilet					toilet					toilet		
Derrick			lounge 				lounge 				lounge 				
Timmy				rubbish				rubbish				rubbish			
Bobbie					vacuum				vacuum				vacuum

Really what the hell does messy and glitchy mean? If you want to show use what the proper output is supposed to look like then post a copy of it...messy and glitchy means nothing from our point of view.

Sorry!

This is what its supposed to look like(you dont have to worry about the numbers, but they represent days. i.e. a duty for each day):

0	1	2	3	4	5	6	7	8	9	10	11	12	13	
Sam	dishes					dishes				        dishes							
Chinky		toilet					toilet			                toilet						
Derrick			lounge 				        lounge 				        lounge 				
Timmy				rubbish				         rubbish			        rubbish			
Bobbie					vacuum				         vacuum

the cout << '\t'; doesn't seem to work halfway through.

And the reason I need to write the code like this is because the user needs to be able to swap those duties around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.