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;
}