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

Home Posts Topics Members FAQ

Find highest and lowest value in a multidimensional array in C?

1 New Member
I can't get it to work to find the highest value in the given matrix. Any ideas? (total C beginner here).

Also in this one i get the user to fill in the array values but which would be the fastest way to have a predefined 2D multiarray?






#include <cstdlib>
#include <iostream>

using namespace std;

const int NODES = 3;
const int CONNECT = 7;
double average = 0;

int getSum (int [][CONNECT]);
void getChart (int [][CONNECT]);
void connectionAvg (int table [][CONNECT]);
int findLowest (int table [][CONNECT]);
int findHighest (int table [][CONNECT]);

int main(int argc, char *argv[])
{
int table [NODES][CONNECT];

cout << "The nodes and connections each, please enter your info tutti frutti: \n\n";

getChart(table);

cout << "The total amount of connections is: "
<< getSum(table) << " Connections\n\n";

connectionAvg(table);

cout << "The lowest amount of connections is : " << findLowest(table) << " Connections\n";
cout << "The highest amount of connections is: " << findHighest(table) << " Connections\n";

//ofstream outData;
//outData.open("results.txt");

system("PAUSE");
return EXIT_SUCCESS;
}

int getSum (int table [][CONNECT])
{
int sum = 0;
for ( int node = 0; node < NODES; node++)
{
for (int connection = 0; connection < CONNECT; connection++)
sum += table [node][connection];
}
return sum;
}

void getChart (int table[][CONNECT])
{
for (int node = 0; node < NODES; node++)
{
for (int connection = 0; connection < CONNECT; connection++)
{
cout << "node " << (node+1) << ", ";
cout << "connection " << (connection+1) << ": ";
cin >> table [node][connection];
}
cout << endl;
}
}

void connectionAvg (int table [][CONNECT])
{
for ( int connection = 0; connection < CONNECT; connection++)
{
int total = 0;
for (int node = 0; node < NODES; node++)
{
total += table [node][connection];
}
average = total/NODES;
cout << "Average connections on connection " << (connection+1)
<< " by all 3 NODES is: " << average << " connections" << endl;
}
}

int findLowest (int table [][CONNECT])
{
int lowest = table [NODES][CONNECT];
for (int node = 0; node < NODES; node++)
{
for (int connection = 0; connection < CONNECT; connection++)
{
if (table [node][connection] < lowest)
lowest = table[node][connection];
}

cout << endl;
}
return lowest;
}

int findHighest (int table [][CONNECT])
{
int highest = table [NODES][CONNECT];
for (int node = 0; node < NODES; node++)
{
for (int connection = 0; connection < CONNECT; connection++)
{
if (table [node][connection] > highest)
highest = table[node][connection];
}

cout << endl;
}
return highest;
}
Aug 27 '15 #1
1 1489
weaknessforcats
9,208 Recognized Expert Moderator Expert
I'm not sure why you are using a multidimensional array.

You might read this: http://bytes.com/topic/c/insights/77...rrays-revealed

This code:

Expand|Select|Wrap|Line Numbers
  1. int findHighest (int table [][CONNECT])
  2.  {
  3.  int highest = table [NODES][CONNECT];
  4. etc...
assigns highest from table[3][7]. However, the last element in the array is
table[2][6]. The same problem is in the lowest function as well. Remember, array indexes count from zero.
Aug 27 '15 #2

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

Similar topics

1
8204
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
10
12165
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
3
16085
by: lostncland | last post by:
I am working on this program. The array has 10 scores. (there is more to this program.) Does the last "for" section make sense? /*Defines a global constant called N throughout the file. ...
30
5212
by: =?Utf-8?B?VGhvbWFzVDIy?= | last post by:
Hello, I have an array that holds 4 values ( they contain random numbers). I would like to find the lowest value (if there is a tie i would like to find one of the tie.) then remove that value....
9
3386
by: raamay | last post by:
i have a table where the records are in the following fashion: firm w1 w3 w4 class abc ltd. b c d b bcd ltd. ...
2
1973
Brandenburg
by: Brandenburg | last post by:
I'm writing a game in visual basic 2008 and things are going fairly well with it for the most part.. well until today.. I can declare a 1 dimensional array of a class just fine but cannot for the...
7
7369
by: Alberto Fortuny | last post by:
Hey guys, any idea as to how to find the lowest value and the highest value in this 2D array? I made the functions to find the lowest and highest, but all im getting on execution is a 1 on both, no...
2
2071
by: antonydoyle | last post by:
Hi Hope someone can help me with this! I'm trying to get a table of data into a multidimensional array. The table fields are as follows; headline
0
7127
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
7391
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...
1
7054
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...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
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...
0
3204
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...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
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...

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.