473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

checking is a 2d array of numbers are in order

hi I'm trying to write a function that check through a 2d array of numbers and check if they are in order or not
e.g 1 2 3
4 5 6 the function will return TURE

3 2 4
6 1 5 will return FALSE

Expand|Select|Wrap|Line Numbers
  1.  int checkPuzzle(int puzzle[][COLS])
  2. {
  3.    for (row=0; row<ROWS; row++)
  4.    {
  5.       for (col=0; col<COLS; col++)
  6.       {
  7.         if (puzzle[row][col] > puzzle[row][col+1]);
  8.         {
  9.           return TRUE
  10.         }       
  11.         else
  12.         {
  13.           return FALSE;
  14.         }
  15.       }
  16.  
  17.   }
  18.  
can anyone help ?
thanks
Apr 26 '07 #1
4 1740
sicarie
4,677 Expert Mod 4TB
hi I'm trying to write a function that check through a 2d array of numbers and check if they are in order or not
e.g 1 2 3
4 5 6 the function will return TURE

3 2 4
6 1 5 will return FALSE


int checkPuzzle(int puzzle[][COLS])
{
for (row=0; row<ROWS; row++)
{
for (col=0; col<COLS; col++)
{
if (puzzle[row][col] > puzzle[row][col+1]);
{
return TRUE
}
else
{
return FALSE;
}
}

}


can anyone help ?
thanks

Please use [ code] and [ /code] tags around your code, it helps greatly with readability.

What do you need help with? You posted code, is there something with that that doesn't work? Is it returning an error?
Apr 26 '07 #2
I need to return true only when the whole array is checked. it steps through the whole array checking if the number aheand of it is larger and will keep on going unitl the end. once a false condition is detected false will be returned
Apr 26 '07 #3
problem is is returning true everytime the one step , i need to return true only when the array has been stepped through
Apr 26 '07 #4
sicarie
4,677 Expert Mod 4TB
I need to return true only when the whole array is checked. it steps through the whole array checking if the number aheand of it is larger and will keep on going unitl the end. once a false condition is detected false will be returned
Okay, so you're having trouble with this line:

if (puzzle[row][col] > puzzle[row][col+1])

What's happening is that because you have 'puzzle[row][col]' those are being resolved to actual values, for instance, if puzzle [0][0] holds the value of 5, 5 is being returned, and if puzzle [0][1] holds 10, 10 is being returned for that, so the compiler sees it as:

if ( 5 > 10 )

I would recommend using the ROWS and row variables directly (not in the array). Then you'll get the actual element number that resides there.
Apr 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
41
by: puzzlecracker | last post by:
Given an array of size n and populated with consecutive integers from 1 to n i.e. in random order. Two integers are removed, meaning zero is placed in their places. Give O (n) efficient algorithm...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
6
by: Paul van Brenk | last post by:
When you run the Shuffle method often enough it will throw exception. And I can't figure out why. Anybody? Paul van Brenk the code: static void Shuffle(){ int ints = { 1, 2, 3, 4, 5, 6,...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
5
by: jar13861 | last post by:
I'm confused on how to write a random array that will only generate 9 different numbers from 1-9. Here is what I have, but its only writing one number.... holder = new Array ( 9 ); var flag =...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
2
by: mindrage00 | last post by:
Hi! I am creating an image gallary where the images are numbered 1, 2, 3 etc. Users will be uploading the images so if i need to delete an image, I need the code to be able to check if that number...
1
by: LittlBUGer | last post by:
Hello. First of all I'm programming in VB.NET/ASP.NET doing a page for a website. Now, to my question.... I have a simple array of integer numbers (15 characters in length) which can hold up to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.