I am to write a program which will prompt the user for a size (NxN) matrix then

1. call a function (generate) that generates the values of the matrix using the formula:
X ij = 1.0/(I + J)
2. call a function (transpose) that finds the transpose to the matrix; call the new matrix XT. A transpose of a matrix is all rows become columns and columns become rows.
3. call a function (multiply) that multiplies matrices X and XT; call the resulting matrix XXT.
Your program should label all output and calls a function which prints a matrix.

I have the following:

#include <iostream>
#include <iomanip.h>
const int size = 100;
void generate (float x[], int n, float&xij)
{
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
cout.width(6);
cout.precision(3);
cout<<x[j]<<"\t";
cout<<endl;
xij = 1.0/(i+j);
}
}
void transpose(int x[], int xt[])
void multiply (int xxt)
{
int x, xt;
xxt = x * xt;
}
main ()
{
int i,j,xt,xxt,x;
cout<<"Enter number of row(s) for the matrix:"<<endl;
cin>>n1>>endl;
cout<<"Enter number of column(s) for the matrix:"<<endl;
cin>>n2>>endl;
void generate (array);
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
cout<<setw(6)precision(3)x[j]<<"\t"
void transpose (x[][], xt[][]);
void multiply (xxt);
}

I keep getting the following errors:

matrix.cpp: In function `void generate(float (*)[100], int, float &)':
matrix.cpp:11: name lookup of `j' changed for new ANSI `for' scoping
matrix.cpp:8:   using obsolete binding at `j'
matrix.cpp: In function `void transpose(int (*)[100], int (*)[100])':
matrix.cpp:17: parse error before `void'
matrix.cpp: In function `void multiply(int)':
matrix.cpp:18: confused by earlier errors, bailing out

You need to pay more attention to semicolons and placement of braces. There are other problems than I identified below, but fix these first.

#include <iostream>
#include <iomanip.h>
const int size = 100;
void generate (float x[][size], int n, float&xij)
{
        for (int i=0; i<n; i++)
        {
                for (int j=0; j<n; j++)
                cout.width(6);
                /* variable j is undefined below this line because of the
                lack of braces.*/
                cout.precision(3);
                        cout<<x[i][j]<<"\t";
                cout<<endl;
                xij = 1.0/(i+j);
        }
}
void transpose(int x[][size], int xt[][size])/*<< what is this???  It looks like a function prototype, but is missiong a semi-colon at the end.  function prototypes normally eppear at the beginning of the file, not scattered throughout the program unit.*/

void multiply (int xxt)
{
        int x, xt;
        xxt = x * xt;
       /* This function does nothing.  It probably should
          return the result of the multiplication.  Where are variables x and
          xt initialized?  they just contain garbage */
}
main ()
{
        int i,j,xt,xxt,x;
        cout<<"Enter number of row(s) for the matrix:"<<endl;
        cin>>n1>>endl;
        cout<<"Enter number of column(s) for the matrix:"<<endl;
        cin>>n2>>endl;
        void generate (array);  /* where is variable `array` defined? */

        for (i=0; i<n; i++)
        {
                for (j=0; j<n; j++)
                cout<<setw(6)precision(3)x[i][j]<<"\t"\

                /* x above is not an array but you are using it like one.  See
                   definition of x at the beginning of main() missing close brace 
                   probably here.*/

void transpose (x[][], xt[][]);
           /* and line below.  these are nothing more than function prototypes.  
              They do not call the functions.  move both lines near the top of the 
              file.*/

        void multiply (xxt);
}

I keep getting the following errors:

matrix.cpp: In function `void generate(float (*)[100], int, float &)':
matrix.cpp:11: name lookup of `j' changed for new ANSI `for' scoping
matrix.cpp:8:   using obsolete binding at `j'
matrix.cpp: In function `void transpose(int (*)[100], int (*)[100])':
matrix.cpp:17: parse error before `void'
matrix.cpp: In function `void multiply(int)':
matrix.cpp:18: confused by earlier errors, bailing out
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.