How would I call the function so the program runs through each option. I've got the program done but everything i run it, the options do not run. Any help? Thanks.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void readMatrix       (double x[][30], int & m, int & n);
void printMatrix      (double x[][30], int m, int n);
int posEltCount       (double x[][30], int m, int n);
void option1       (double a[][30], int m, int n);
void option2       (const double a[][30], double b[][30], int m, int n);
void option3       (double a[][30], int m, int n);
void option4       (double a[][30], int m, int n);
int main ()
{
    double a[30][30];
    double b[30][30];
    int m1, n1;
    int p, q;
    int positiveCount;
    bool goAgain = true;
    char response;

    while ( goAgain == true)
    {
          readMatrix  (a, m1, n1);
          readMatrix  (b, p, q);
          printMatrix (a, m1, n1);
          printMatrix (b, p, q);
         
          positiveCount = posEltCount (a,m1,n1);
         
          cout << "Number positive elements in matrix a: " << positiveCount << endl << endl;
          positiveCount = posEltCount (b,p,q);
          cout << "Number positive elements in matrix b: " << positiveCount << endl << endl;
          cout << "Go again? y/n: ";
          cin >> response;
          if(response == 'n') goAgain = false;
          cin.ignore(80,'\n');
         
    }
    return 0;  
}        
void readMatrix (double x[][30], int & m, int & n)
{
     int i, j;
     ifstream inputFile;
     char filename[51];
     cout << "Enter filename: ";
     cin.getline (filename, 51);
     cout << endl;
     inputFile.open (filename);
     inputFile >> m >> n;
     
     for (i=0; i < m; i++)
     for (j=0; j < n; j++)
          inputFile >> x[i][j];
     inputFile.clear ();
     inputFile.close ();
}
void printMatrix (double x[][30], int m, int n)
{
     int i, j;
     cout << endl << endl;
     for (i=0; i < m; i++)
     {
         for (j=0; j < n; j++)
         {
             cout << fixed << setprecision(2) << setw(8) << x[i][j];
         }
         cout << endl << endl;
         cout << "   Size " << m << "x" << n << endl << endl;
     }
}
int posEltCount (double x[][30], int rows, int cols)
{
         int count = 0;
         for (int i=0; i < rows; i++)
             for (int j=0; j < cols; j++)
                  if (x[i][j] > 0.0) count++;
     return count;
}
void option1 (double a[][30], int m, int n)
{
     double posElementsum;
     double negElementsum;
     int i;
     int j;
     for (i=0; i <= m-1; i++)
     for (j=1; j <= n-1; j++)
     if (a[i][j] > 0)
     posElementsum = posElementsum + a[i][j];
     if (a[i][j] < 0)
     negElementsum = negElementsum + a[i][j];
     cout << "Positive Element Sum = " << setprecision(2) << fixed << right << posElementsum << endl << endl;
     cout << "Negative Element Sum = " << negElementsum << endl << endl;
}
void option2 (const double a[][30], const double b[][30], int m, int n)
{
     int i, j;
     double c;
     for ( i=0; i < m * n; i++ )
     if (a[i] != b[i])
     printf( "Difference at %d by %d\n", i / n, i % n );
     
}
void option3 (double a[][30], int m, int n)
{
     
     int i, j;
     for (i=0; i <= m-1; i++)
     for (j=0; j <= n-1; j++)
     
     if(a[i][j] == a[j][i])
     cout << "Matrix a is symmetric" << endl;
     else
     cout << "Matrix a is not symmetric" << endl;
}
     

void option4 (double a[][30], int m, int n)
{
     int i,j;
     double rowSum[30];
     for (i=0; i<m; i++)
     rowSum[i] = 0;
     for (i=0; i<m; i++)
     for (j=0; j<n; j++)
     rowSum[i] += a[i][j];

     for (i=0; i<m-1; i++)
     for (j=(i+1); j<m; j++)
     if ( rowSum[i] == rowSum[j])
        cout << "Matrix a has two equal rows" << endl << endl;
     else
        cout << "Matrix a has no equal rows" << endl << endl;
     
     
}

How would I call the function so the program runs through each option. I've got the program done but everything i run it, the options do not run. Any help? Thanks.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void readMatrix       (double x[][30], int & m, int & n);
void printMatrix      (double x[][30], int m, int n);
int posEltCount       (double x[][30], int m, int n);
void option1       (double a[][30], int m, int n);
void option2       (const double a[][30], double b[][30], int m, int n);
void option3       (double a[][30], int m, int n);
void option4       (double a[][30], int m, int n);
int main ()
{
    double a[30][30];
    double b[30][30];
    int m1, n1;
    int p, q;
    int positiveCount;
    bool goAgain = true;
    char response;

    while ( goAgain == true)
    {
          readMatrix  (a, m1, n1);
          readMatrix  (b, p, q);
          printMatrix (a, m1, n1);
          printMatrix (b, p, q);
         
          positiveCount = posEltCount (a,m1,n1);
         
          cout << "Number positive elements in matrix a: " << positiveCount << endl << endl;
          positiveCount = posEltCount (b,p,q);
          cout << "Number positive elements in matrix b: " << positiveCount << endl << endl;
          cout << "Go again? y/n: ";
          cin >> response;
          if(response == 'n') goAgain = false;
          cin.ignore(80,'\n');
         
    }
    return 0;  
}        
void readMatrix (double x[][30], int & m, int & n)
{
     int i, j;
     ifstream inputFile;
     char filename[51];
     cout << "Enter filename: ";
     cin.getline (filename, 51);
     cout << endl;
     inputFile.open (filename);
     inputFile >> m >> n;
     
     for (i=0; i < m; i++)
     for (j=0; j < n; j++)
          inputFile >> x[i][j];
     inputFile.clear ();
     inputFile.close ();
}
void printMatrix (double x[][30], int m, int n)
{
     int i, j;
     cout << endl << endl;
     for (i=0; i < m; i++)
     {
         for (j=0; j < n; j++)
         {
             cout << fixed << setprecision(2) << setw(8) << x[i][j];
         }
         cout << endl << endl;
         cout << "   Size " << m << "x" << n << endl << endl;
     }
}
int posEltCount (double x[][30], int rows, int cols)
{
         int count = 0;
         for (int i=0; i < rows; i++)
             for (int j=0; j < cols; j++)
                  if (x[i][j] > 0.0) count++;
     return count;
}
void option1 (double a[][30], int m, int n)
{
     double posElementsum;
     double negElementsum;
     int i;
     int j;
     for (i=0; i <= m-1; i++)
     for (j=1; j <= n-1; j++)
     if (a[i][j] > 0)
     posElementsum = posElementsum + a[i][j];
     if (a[i][j] < 0)
     negElementsum = negElementsum + a[i][j];
     cout << "Positive Element Sum = " << setprecision(2) << fixed << right << posElementsum << endl << endl;
     cout << "Negative Element Sum = " << negElementsum << endl << endl;
}
void option2 (const double a[][30], const double b[][30], int m, int n)
{
     int i, j;
     double c;
     for ( i=0; i < m * n; i++ )
     if (a[i] != b[i])
     printf( "Difference at %d by %d\n", i / n, i % n );
     
}
void option3 (double a[][30], int m, int n)
{
     
     int i, j;
     for (i=0; i <= m-1; i++)
     for (j=0; j <= n-1; j++)
     
     if(a[i][j] == a[j][i])
     cout << "Matrix a is symmetric" << endl;
     else
     cout << "Matrix a is not symmetric" << endl;
}
     

void option4 (double a[][30], int m, int n)
{
     int i,j;
     double rowSum[30];
     for (i=0; i<m; i++)
     rowSum[i] = 0;
     for (i=0; i<m; i++)
     for (j=0; j<n; j++)
     rowSum[i] += a[i][j];

     for (i=0; i<m-1; i++)
     for (j=(i+1); j<m; j++)
     if ( rowSum[i] == rowSum[j])
        cout << "Matrix a has two equal rows" << endl << endl;
     else
        cout << "Matrix a has no equal rows" << endl << endl;
     
     
}

any one?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.