14 Replies - 2748 Views - Last Post: 05 February 2010 - 04:40 AM Rate Topic: -----

#1 this_is_dhruv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 10-January 10

c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 06:47 AM

i wrote a c++ program, basically it's a menu driven program to add. subtract, multiply and divide two matrices.

i executed it and it found 26 errors, i am not able to clear them, please help me and do tell me where i got wrong

#include<iostream.h>
#include<conio.h>
float add(float, float);
float sub(float, float);
float mult(float, float);
float div(float, float);
int main()
{
	int i,j,ch;
	float a[3][3],b[3][3];
	cout<<"Enter Matrix A \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
		cin>>a[i][j];
		}
	}
	cout<<"Enter Matrix B \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>b[i][j];
		}
	}
	//Displaying Matrices
	cout<<"Matrix A"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Matrix B"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Enter 1 for Addition"<<"\n";
	cout<<"Enter 2 for Subtraction \n";
	cout<<"Enter 3 for multiplication \n";
	cout<<"Enter 4 for Division \n";
	cin>>ch;
	switch(ch)
	{
	case 1: int y=add(a[][],b[][]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<y[i][j]<<"\t";
				}
				cout<<"\n";
			}
	case 2: int x=sub(a[][], b[][]);
			for(i=0;i<3;i++)
			{
			  for(j=0;j<3;j++)
			  {
				cout<<x[i][j]<<"\t";
			  }
			cout<<"\n";
			}
	case 3: int z=mult(a[][],b[][]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<z[i][j]<<"\t";
				}
				cout<<"\n";
			}
	case 4: int w=div(a[][].b[][]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<w[i][j]<<"\t";
				}
				cout<<"\n";
			}
	default :cout<<"Wrong Choice Entered, Aborting";
			 exit(0);
			 }
	return 0;
}
float add(c[][],d[][])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]+d[i][j];
		}
	}
	return e[i][j];
}
float sub(c[][],d[][])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]-d[i][j];
		}
	}
	return e[i][j];
}
float mult(c[][],d[][])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]*d[i][j];
		}
	}
	return e[i][j];
}
float div(c[][],d[][])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]/d[i][j];
		}
	}
	return e[i][j];
}


**Mod Edit: Changed title to be more descriptive**

This post has been edited by OliveOyl3471: 31 January 2010 - 01:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: c++ matrix program errors: undeclared identifier, cannot convert param

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,415
  • Joined: 23-August 08

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 06:57 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 07:07 AM

post exact errors that are coming
Was This Post Helpful? 0
  • +
  • -

#4 freetosay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 07:32 AM

It will help on the debugging if posting exact errors.

It seems that there are some obvious issues in the code.
> Place 'break' in the last place of each 'case' branch to jump out the handling.
> The calculation rountes are declared with inproper in and return paramaters according to your implementation intention.
Was This Post Helpful? 0
  • +
  • -

#5 this_is_dhruv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 10-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 10:09 PM

i tried adding break in the switch() statements, but no luck.
i got these errors :
--------------------Configuration: p1 - Win32 Debug--------------------
Compiling...
p1.cpp
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(53) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(58) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(58) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(63) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(68) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(68) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(73) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(78) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(78) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(83) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(88) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(88) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(94) : error C2065: 'exit' : undeclared identifier
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(98) : error C2065: 'c' : undeclared identifier
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(98) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(99) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(99) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(111) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(112) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(112) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(124) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(125) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(125) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(137) : error C2059: syntax error : ']'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(138) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(138) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

p1.exe - 26 error(s), 0 warning(s)

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,415
  • Joined: 23-August 08

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 29 January 2010 - 11:09 PM

For you to read
Was This Post Helpful? 0
  • +
  • -

#7 this_is_dhruv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 10-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 03:22 AM

View PostJackOfAllTrades, on 29 Jan, 2010 - 10:09 PM, said:



thnks, it helped me solving most problems

my rewritten code is this :
#include<iostream.h>
#include<conio.h>
float add(float, float);
float sub(float, float);
float mult(float, float);
float div(float, float);
int main()
{
	int i,j,ch;
	float a[3][3],b[3][3];
	//Accepting Matrices
	cout<<"Enter Matrix A \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
		cin>>a[i][j];
		}
	}
	cout<<"Enter Matrix B \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>b[i][j];
		}
	}
	//Displaying Matrices
	cout<<"Matrix A"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Matrix B"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Enter 1 for Addition"<<"\n";
	cout<<"Enter 2 for Subtraction \n";
	cout<<"Enter 3 for multiplication \n";
	cout<<"Enter 4 for Division \n";
	cin>>ch;
	switch(ch)
	{
	case 1: int y=add(a[3][3],b[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<y[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	case 2: int x=sub(a[3][3],b[3][3]);
			for(i=0;i<3;i++)
			{
			  for(j=0;j<3;j++)
			  {
				cout<<x[i][j]<<"\t";
			  }
			cout<<"\n";
			}
			break;
	case 3: int z=mult(a[3][3],b[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<z[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	case 4: int w=div(a[3][3],b[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<w[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	default :cout<<"Wrong Choice Entered, Aborting";
			 exit(0);
			 }
	return 0;
}
float add(float c[3][3],float d[3][3])
{
	int k,l; 
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]+d[i][j];
		}
	}
	return e[i][j];
}
float sub(float c[3][3],float d[3][3])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]-d[i][j];
		}
	}
	return e[i][j];
}
float mult(float c[3][3],float d[3][3])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]*d[i][j];
		}
	}
	return e[i][j];
}
float div(float c[3][3],float d[3][3])
{
	int k,l;
	float e[3][3];
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[i][j]=c[i][j]/d[i][j];
		}
	}
	return e[i][j];
}


and i still get errors :
--------------------Configuration: p1 - Win32 Debug--------------------
Compiling...
p1.cpp
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(59) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(59) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : error C2360: initialization of 'y' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : see declaration of 'y'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(69) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(69) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : error C2360: initialization of 'x' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : see declaration of 'x'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : error C2360: initialization of 'y' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : see declaration of 'y'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(79) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(79) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : error C2360: initialization of 'z' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : see declaration of 'z'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : error C2360: initialization of 'x' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : see declaration of 'x'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : error C2360: initialization of 'y' is skipped by 'case' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : see declaration of 'y'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(89) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(89) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(94) : error C2361: initialization of 'w' is skipped by 'default' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : see declaration of 'w'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(94) : error C2361: initialization of 'z' is skipped by 'default' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : see declaration of 'z'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(94) : error C2361: initialization of 'x' is skipped by 'default' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : see declaration of 'x'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(94) : error C2361: initialization of 'y' is skipped by 'default' label
		C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : see declaration of 'y'
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(95) : error C2065: 'exit' : undeclared identifier
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(107) : error C2065: 'i' : undeclared identifier
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(107) : error C2065: 'j' : undeclared identifier
Error executing cl.exe.

p1.exe - 21 error(s), 4 warning(s)

Was This Post Helpful? 0
  • +
  • -

#8 dave007  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 49
  • Joined: 24-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 05:18 AM

Change You function signature as shown below,

float add(float[][3], float[][3]);
float sub(float[][3], float[][3]);
float mult(float[][3], float[][3]);
float div(float[][3], float[][3]);



One more thing - You can return multiple value from function. In other words, you can return only single value from the function.

In your case, you care returning single element of array,
	return e[i][j];



This is not what you want. You need to pass one more parameter(2d array) to function and copy your resultant matrix to this, in this case you don't need to return anything.

I have updated one function for your understanding, look at below code,
//function signature
void add(float [][3],float [][3], float [][3]);

//function definition/body
void add(float c[3][3],float d[3][3], float e[3][3])
{
	int k,l;
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]+d[k][l];  //use k and l. 
											   // i and j are not defined in this function
		}
	}
}

//function calling
//int c[3][3]
add(a, b, c);  //declare one more 2d array for result. c[3][3]

//then print c




There are few other changes you have to do to make your program run,
1. write using namespace std; at the top, after including header files


Do the changes and check...

You should also read this.. Returning Array

Hope it will solve all your errors... :)
Was This Post Helpful? 0
  • +
  • -

#9 AsadHanif  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 19-December 09

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 05:18 AM



I found some basic errors in your program...
I have mentioned that where are errors and why they are interrupting you...... Please have a look....

I hope you will solve it correctly... :-)

Now read your errors.......

int y=add(a[3][3],b[3][3]); // ???
// since your add function has return type float but you are storing in integer type
// variable, this is logically wrong.......

cout<<y[i][j]<<"\t"; // ???
// since you are declaring ya as simple variable but you are trying to use it
// as array, this is wrong

// on the same way you are doing mistake in all cases

int x=sub(a[3][3],b[3][3]); // ???

cout<<x[i][j]<<"\t"; // ???

int z=mult(a[3][3],b[3][3]); // ???

cout<<z[i][j]<<"\t"; // ???

int w=div(a[3][3],b[3][3]); // ???

cout<<w[i][j]<<"\t"; // ???

// remove these errors then you'll be free from errors


// some logical mistakes in all functions

float add(float c[3][3],float d[3][3])
{
int k,l;
float e[3][3];
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
e[i][j]=c[i][j]+d[i][j];
}
}
return e[i][j]; // here you are returning element of array which is out of
// your access, means in 3 X 3 array last element is always
// e[2][2] because in C/ C++ index of array always starts
// from 0...... I know here you want to return whole 2D array
// but for your information in C/C++ you can not return array..
// for this you have to use some other ways, like pass by
// pointers or pass by reference.....
}
float sub(float c[3][3],float d[3][3])
{
int k,l;
float e[3][3];
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
e[i][j]=c[i][j]-d[i][j];
}
}
return e[i][j]; // same error as above
}
float mult(float c[3][3],float d[3][3])
{
int k,l;
float e[3][3];
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
e[i][j]=c[i][j]*d[i][j];
}
}
return e[i][j]; // same error as above
}
float div(float c[3][3],float d[3][3])
{
int k,l;
float e[3][3];
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
e[i][j]=c[i][j]/d[i][j];
}
}
return e[i][j]; // same error as above
}

Was This Post Helpful? 0
  • +
  • -

#10 dave007  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 49
  • Joined: 24-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 05:20 AM

Typo error in above statement... have changed it... :^:

One more thing - You can NOT return multiple values from the function. In other words, you can return only single value from the function.
Was This Post Helpful? 0
  • +
  • -

#11 this_is_dhruv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 10-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 05:51 AM

View Postdave007, on 30 Jan, 2010 - 04:18 AM, said:

Change You function signature as shown below,

float add(float[][3], float[][3]);
float sub(float[][3], float[][3]);
float mult(float[][3], float[][3]);
float div(float[][3], float[][3]);



One more thing - You can return multiple value from function. In other words, you can return only single value from the function.

In your case, you care returning single element of array,
	return e[i][j];



This is not what you want. You need to pass one more parameter(2d array) to function and copy your resultant matrix to this, in this case you don't need to return anything.

I have updated one function for your understanding, look at below code,
//function signature
void add(float [][3],float [][3], float [][3]);

//function definition/body
void add(float c[3][3],float d[3][3], float e[3][3])
{
	int k,l;
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]+d[k][l];  //use k and l. 
											   // i and j are not defined in this function
		}
	}
}

//function calling
//int c[3][3]
add(a, b, c);  //declare one more 2d array for result. c[3][3]

//then print c




There are few other changes you have to do to make your program run,
1. write using namespace std; at the top, after including header files


Do the changes and check...

You should also read this.. Returning Array

Hope it will solve all your errors... :)


thanks for the help.

i corrected my work, and now it looks like this :
#include<iostream.h>
#include<conio.h>
void add(float[3][3], float[3][3], float [3][3]);
void sub(float[3][3], float[3][3], float [3][3]);
void mult(float[3][3], float[3][3], float [3][3]);
void div(float[3][3], float[3][3], float [3][3]);
int main()
{
	int i,j,ch;
	float a[3][3],b[3][3],c[3][3];
	//Accepting Matrices
	cout<<"Enter Matrix A \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
		cin>>a[i][j];
		}
	}
	cout<<"Enter Matrix B \n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>b[i][j];
		}
	}
	//Displaying Matrices
	cout<<"Matrix A"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Matrix B"<<"\n";
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cout<<a[i][j]<<"\t";
		}
		cout<<"\n";
	}
	cout<<"Enter 1 for Addition"<<"\n";
	cout<<"Enter 2 for Subtraction \n";
	cout<<"Enter 3 for multiplication \n";
	cout<<"Enter 4 for Division \n";
	cin>>ch;
	switch(ch)
	{
	case 1: add(a[3][3],b[3][3],c[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<c[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	case 2: sub(a[3][3],b[3][3],c[3][3]);
			for(i=0;i<3;i++)
			{
			  for(j=0;j<3;j++)
			  {
				cout<<c[i][j]<<"\t";
			  }
			cout<<"\n";
			}
			break;
	case 3: mult(a[3][3],b[3][3],c[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<c[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	case 4: div(a[3][3],b[3][3],c[3][3]);
			for(i=0;i<3;i++)
			{
				for(j=0;j<3;j++)
				{
					cout<<c[i][j]<<"\t";
				}
				cout<<"\n";
			}
			break;
	default :cout<<"Wrong Choice Entered, Aborting";
	}
	return 0;
}
void add(float c[3][3],float d[3][3],float e[3][3])
{
	int k,l; 
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]+d[k][l];
		}
	}
}
void sub(float c[3][3],float d[3][3],float e[3][3])
{
	int k,l;
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]-d[k][l];
		}
	}
}
void mult(float c[3][3],float d[3][3],float e[3][3])
{
	int k,l;
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]*d[k][l];
		}
	}
}
void div(float c[3][3],float d[3][3],float e[3][3])
{
	int k,l;
	for(k=0;k<3;k++)
	{
		for(l=0;l<3;l++)
		{
			e[k][l]=c[k][l]/d[k][l];
		}
	}
}


and i get these errors now.
--------------------Configuration: p1 - Win32 Debug--------------------
Compiling...
p1.cpp
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(54) : error C2664: 'add' : cannot convert parameter 1 from 'float' to 'float [][3]'
		There is no context in which this conversion is possible
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(64) : error C2664: 'sub' : cannot convert parameter 1 from 'float' to 'float [][3]'
		There is no context in which this conversion is possible
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(74) : error C2664: 'mult' : cannot convert parameter 1 from 'float' to 'float [][3]'
		There is no context in which this conversion is possible
C:\Documents and Settings\Dhruv Arora\Desktop\p1.cpp(84) : error C2664: 'div' : cannot convert parameter 1 from 'float' to 'float [][3]'
		There is no context in which this conversion is possible

Was This Post Helpful? 0
  • +
  • -

#12 dave007  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 49
  • Joined: 24-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 30 January 2010 - 05:58 AM

Change your function calling,

add(a,b,c); // do not specify the dimension



same for sub,mult and div. and it will work

All the Best.. :^:
Was This Post Helpful? 0
  • +
  • -

#13 ymihere  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 31 January 2010 - 11:17 AM

This Is A Correct program .....Please Go Through It...
#include<iostream.h>
#include<conio.h>
void add();
void sub();
void mult();
void div();
float a[3][3],b[3][3],c[3][3];
int main()
{
	int i,j,ch;

	//Accepting Matrices
	cout<<"Enter Matrix A \n";
	for(i=0;i<3;i++)
	{
	for(j=0;j<3;j++)
	{
	cin>>a[i][j];
	}
	}
	clrscr();
	cout<<"Enter Matrix B \n";
	for(i=0;i<3;i++)
	{
	for(j=0;j<3;j++)
	{
		cin>>b[i][j];
	}
	}
	//Displaying Matrices
	cout<<"Matrix A"<<"\n";
	for(i=0;i<3;i++)
	{
	for(j=0;j<3;j++)
	{
		cout<<a[i][j]<<"\t";
	}
	cout<<"\n";
	}
	cout<<"Matrix B"<<"\n";
	for(i=0;i<3;i++)
	{
	for(j=0;j<3;j++)
	{
		cout<<b[i][j]<<"\t";
	}
	cout<<"\n";
	}
	cout<<"\n\n\\n";
	cout<<"Enter 1 for Addition"<<"\n";
	cout<<"Enter 2 for Subtraction \n";
	cout<<"Enter 3 for multiplication \n";
	cout<<"Enter 4 for Division \n";
	cin>>ch;
	switch(ch)
	{
	case 1: add();
		for(i=0;i<3;i++)
		{
		for(j=0;j<3;j++)
		{
			cout<<c[i][j]<<"\t";
		}
		cout<<"\n";
		}
		break;
	case 2: sub();
		for(i=0;i<3;i++)
		{
		  for(j=0;j<3;j++)
		  {
		cout<<c[i][j]<<"\t";
		  }
		cout<<"\n";
		}
		break;
	case 3: mult();
		for(i=0;i<3;i++)
		{
		for(j=0;j<3;j++)
		{
			cout<<c[i][j]<<"\t";
		}
		cout<<"\n";
		}
		break;
	case 4: div();
		for(i=0;i<3;i++)
		{
		for(j=0;j<3;j++)
		{
			cout<<c[i][j]<<"\t";
		}
		cout<<"\n";
		}
		break;
	default :cout<<"Wrong Choice Entered, Aborting";
	}
	return 0;
}
void add()
{
	int k,l;
	for(k=0;k<3;k++)
	{
	for(l=0;l<3;l++)
	{
		c[k][l]=a[k][l]+b[k][l];
	}
	}
}
void sub()
{
	int k,l;
	for(k=0;k<3;k++)
	{
	for(l=0;l<3;l++)
	{
		c[k][l]=a[k][l]-b[k][l];
	}
	}
}
void mult()
{
	int k,l;
	for(k=0;k<3;k++)
	{
	for(l=0;l<3;l++)
	{
		c[k][l]=a[k][l]*b[k][l];
	}
	}
}
void div()
{
	int k,l;
	for(k=0;k<3;k++)
	{
	for(l=0;l<3;l++)
	{
		c[k][l]=a[k][l]/b[k][l];
	}
	}
}


Was This Post Helpful? 0
  • +
  • -

#14 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 31 January 2010 - 12:22 PM

What should we do with it? It's up to you to test it ...
BTW it compiles. Have fun!
Was This Post Helpful? 0
  • +
  • -

#15 this_is_dhruv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 10-January 10

Re: c++ matrix program errors: undeclared identifier, cannot convert param

Posted 05 February 2010 - 04:40 AM

thanks all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1