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

Home Posts Topics Members FAQ

Find highest and lowest value in a multidimensiona l 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(t able);

cout << "The lowest amount of connections is : " << findLowest(tabl e) << " Connections\n";
cout << "The highest amount of connections is: " << findHighest(tab le) << " Connections\n";

//ofstream outData;
//outData.open("r esults.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 1496
weaknessforcats
9,208 Recognized Expert Moderator Expert
I'm not sure why you are using a multidimensiona l 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
8255
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 RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
10
12200
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 help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
3
16092
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. Note that N = 10. */ #define N 10 #include <iostream> using namespace std;
30
5233
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. I am new to Programming and C#. Thanks for any help you can provide Thomas
9
3393
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. c c d c cde ltd. a d b a def ltd. d d d d as clearly indicated, the highest category among w1,w3 and w4 makes up the...
2
1980
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 life of me get the syntax right for a multidimensional array. I usually don't have many issues in writing in VB but this is the first large scale program I have ever written in VB2008 and the 1st large scale uses of classes in VB as well Here is my...
7
7394
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 matter what number i input. Here's my code #include <cstdlib> #include <iostream> using namespace std; const int MONKEYS = 3; const int DAYS = 7; double average = 0;
2
2085
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
8466
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8813
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7412
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4208
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1791
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.