473,587 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checking is a 2d array of numbers are in order

11 New Member
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 1746
sicarie
4,677 Recognized Expert Moderator Specialist
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
silversnake
11 New Member
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
silversnake
11 New Member
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 Recognized Expert Moderator Specialist
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
3253
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)) CType(local4, Short) = CType(src, Short)
41
2207
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 to find them?
21
3191
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a...
6
7850
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, 7, 8, 9, 0 };
3
3725
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 lot different from what the pros around here use. I really need help with debugging some program errors more than anything, even though my coding...
5
2073
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 = true; var rannum = Math.floor( 1 + Math.random() * 9 ); for (var j = 0; j < 9; j++) {
24
3426
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 declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
2
1236
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 has been deleted and replace it with the next uploaded image. I have the code pulling from a txt file with a counter to name each file. The...
1
1283
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 2000 items. What I basically need to do is output these numbers to a PDF file I'm creating on the fly and I can only fit a certain amount of numbers...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.