By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

im trying to finish a program just before the deadline

P: n/a
im trying to finish a program, but been having some dificulties in passing
a bidimensional array at a function...(til now nobody could help me) final
result should be a program that adds, subtracts and multiply two arrays,
but havent been able to do the rest once that this is right in the basis
of the program... this is what have done so far (sorry for the bad "Eng"
im trying but im portuguese so people say i sound like "Borat")!

#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <fstream.h>
#include <ctype.h>

using namespace std;

//mxa
int L1;
int C1;

//mxb
int L2;
int C2;

void menu ();
void mxa ();
void mxb ();
void calc ();

void mxa (){
// A

cout<< "Matrix A" << endl;
cout<< "Lines:" << endl;
cin >>L1;
cout<< "Colums:" << endl;
cin>> C1;
int mx1 [L1][C1];
cout<<endl;
for (int m=0; m<L1; m++){
for (int n=0; n<C1; n++){
cout<< " Matrix element " << m+1 << " , " << n+1 <<endl;
cin>> mx1 [m][n];
cout<< endl;}}

for (int m=0; m<L1; m++){
for (int n=0; n<C1; n++){
cout<< mx1 [m][n]; }
cout<<endl;}

calc (mx1)
mxb();

}//Eo A

void mxb (){
//B

cout<< "Matrix B" << endl;
cout<< "Lines:" << endl;
cin>> L2;
cout<< "Colums :" << endl;
cin>> C2;
int mx2 [L2][C2];
cout<<endl;

for (int m=0; m<L2; m++){
for (int n=0; n<C2; n++){
cout<< "Matrix element " << m+1 << " , " << n+1 <<endl;
cin>> mx2 [m][n];
cout<< endl;}}

for (int m=0; m<L2; m++){
for (int n=0; n<C2; n++){
cout<< mx2 [m][n]; }
cout<<endl;}

calc (mx2);
}//Eo B

void calc (int a[][C1], int b[][C2]){ // <-------------------
/*
Here is the tricky part, for what i've seen and read i believe
that this should be right but unfortunately it just doesnt work
//using Dev-C++ 4.9.9.0>
*/

system("cls");
}//Eo calc

void menu (){
int opt;
cout<< "Main menu:" << endl;
cout<< "1 - Mx A" << endl;
cout<< "2 - Mx B" << endl;
cout<< "3 - Calc "<< endl;
cin>> opt;
if (opcao == 1) {mxa();}
else if (opcao ==2) {mxb ();}
else if (opcao == 3) { calc ();}

}//Eo Mmenu

int main(){
system("cls");
cout<< "Mx Calc 0.9 RC"<< endl;
cout<< "****************"<< endl;
cout<< endl;

menu ();

system("PAUSE");
return 0;
}
Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<4d******************************@localhost.talkab outprogramming.com>
giambi <gi****@sapo.pt> wrote:
#include <iostream>
In the future, C++ questions go to comp.lang.c++. You've also posted
much more code than is relevant to your problem, making the crux of
your question more difficult to discern.
#include <conio.h>
Non-standard header - not kosher for either comp.lang.c or
comp.lang.c++.

But on to the real issue...
int L1;
int C1; void calc (int a[][C1], int b[][C2]){ // <-------------------

^^ ^^

In C, these must be compile-time constants (the phrase "integral
constant" may apply...), and the same may also hold in C++ (I've
crossposted there in case I am incorrect). If you pass an int**, you
should be fine, although the use of global variables isn't the best
way to tackle this.

--
Christopher Benson-Manica
ataru(at)cyberspace.org
Nov 14 '05 #2

P: n/a
(c.l.c restored, as C answer wasn't complete and I don't read ++)
On Tue, 4 Jan 2005 23:05:59 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote:
<4d******************************@localhost.talkab outprogramming.com>
giambi <gi****@sapo.pt> wrote:
#include <iostream>


In the future, C++ questions go to comp.lang.c++. You've also posted
much more code than is relevant to your problem, making the crux of
your question more difficult to discern.
#include <conio.h>


Non-standard header - not kosher for either comp.lang.c or
comp.lang.c++.

But on to the real issue...
int L1;
int C1;

void calc (int a[][C1], int b[][C2]){ // <-------------------

^^ ^^

In C, these must be compile-time constants (the phrase "integral
constant" may apply...), and the same may also hold in C++ (I've
crossposted there in case I am incorrect). If you pass an int**, you
should be fine, although the use of global variables isn't the best
way to tackle this.


In C99 (or ganuck) they may be runtime (but positive) expressions. In
C++, as in C89, they must be integral constant expressions; C++ is
more liberal as to what is an i.c.e. but this case still isn't.

Using an int** _which you have set to point to correctly allocated
space(s)_ is one solution. In C++, another is nested std::vector<>, or
a new'ed array of std::vector but that's yucky.
- David.Thompson1 at worldnet.att.net
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.