im trying to finish a program just before the deadline

G

giambi

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

Christopher Benson-Manica

<4d1e4b0ea11d356fa8d32e29b19b96f5@localhost.talkaboutprogramming.com>
giambi said:
#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.
 
D

Dave Thompson

(c.l.c restored, as C answer wasn't complete and I don't read ++)
<4d1e4b0ea11d356fa8d32e29b19b96f5@localhost.talkaboutprogramming.com>
giambi said:
#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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,415
Latest member
SharonCran

Latest Threads

Top