Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

C++ Matrices Question


  • Please log in to reply

#16
goldfish04

goldfish04

    Member

  • Topic Starter
  • Member
  • PipPip
  • 11 posts
So, If I use this.. .would it work also what would I want my loop to be?? Another for loop or just an if statement or a do while??

if (nums[i][t] != 0 && nums[i][t] !=0)
{
numsquares++
}
  • 0

Advertisements


#17
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts

if (nums[i][t] != 0 && nums[i][t] !=0)

This code is checking the exact same thing twice. That's not going to do you any good. I'm not sure what you are trying to do here. Perhaps you are trying to address the problem of remembering what squares you have already checked. This will require a second matrix of the same size as your input matrix (10 x 10). This matrix will hold bool values instead of int values, and should initially be full of false's.

Important:
I need to mention here, that if you don't have a very good idea of where to start on this part of the homework, which from your posts so far it doesn't seem like you do, I would really strongly recommend that you get help from the professor of your class that assigned this. I say this because it is a pretty complicated algorithm, and I think it's going to be difficult to understand it through an online forum. I think you will save yourself a lot of pain if you get some face-to-face help. That said, I will certainly continue to answer your posts and give you pointers in the right direction. I am not, however, just going to code the thing for you, or tell you exactly how to do it.

also what would I want my loop to be?? Another for loop or just an if statement or a do while??

The kind of loop you need to use is determined by what you are trying to do. Here you need to loop through each element of the matrix and do something. That should sound familiar. It's just like when you read the matrix from the file. At that point you looped through each element of the matrix and did something else (read it from the file). So the loop you use now should be the same kind you used when you read the matrix in - to quote your own code:

for(i = 0; i < 3; i++)
{
	for(t = 0; t < 3; t++)
	{
// Do your stuff here (this is where you read the matrix in before)
	}
}

The stuff you need to do here in this loop is much more complicated than just checking to see if the value is zero or not. (This is where you really need to talk to someone in person about what to do.) You need to write a seperate function to do it. You should pass to the function the matrix containing the int values, the matrix containing the bool values, and the current location of the loop (i and t). The function should return the size of the block at that location. If the function didn't find a block, it should return zero.

Good luck,
Ricci
  • 0

#18
goldfish04

goldfish04

    Member

  • Topic Starter
  • Member
  • PipPip
  • 11 posts
No, Of course I was not looking for someone to write it for me just looking for some guidance etc. You gave what I was looking for... i will write the code of course and talk to the prof and try to figure things out.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP