C/Visual C - AYUDA error de compilación en C++

 
Vista:

AYUDA error de compilación en C++

Publicado por Luis Alberto Guisado Mena (4 intervenciones) el 04/06/2011 04:38:38
Quisiera que alguien me diga el error que estoy cometiendo en esta codificación. Uso el Borland C++ 5.02
Estoy practicando el uso de funciones y cuando compilo este programa me sale un error que dice más o menos así: " Cannot convert 'float ( *)[10]' to 'float' "

El código es el siguiente:

include <iostream.h>
# include <stdlib.h>
# include <conio.h>
# include <stdio.h>
# include <windows.h>
# define subraya "-----------------------------------"

//1. DECLARACIÓN DE FUNCIONES (PROTOTIPOS) ////////////////////////////////////////…

void Rango();
void LlenarM(float);
void Opc();
void RealizaOp(char);
void MostrarM(float);


//2. DECLARACIÓN DE VARIABLES GLOBALES ////////////////////////////////////////…

int f, c;
float A[10][10], B[10][10], C[10][10];

//3. DEFINICIÓN DE FUNCIONES (IMPLEMENTACIÓN DE LOS PROTOTIPOS)

//FUNCIÓN QUE PERMITE LA ENTRADA DE FILAS Y COLUMNAS DE UNA MATRIZ

void Rango()
{
clrscr();
system("title DIMENSIONES DE MATRIZ"); system("color 1e");
gotoxy(15,5); cout<<"DIMENSIONES DE LA MATRIZ";
gotoxy(10,6); cout<<subraya;
gotoxy(10,12); cout<<"# FILAS = "; cin>>f;
gotoxy(10,13); cout<<"# COLUMNAS = "; cin>>c;
}



//FUNCIÓN QUE PERMITE EL LLENADO DE LOS ELEMENTOS DE UNA MATRIZ

void LlenarM(float M[10][10])
{
int i,j;
clrscr();

system("title LLENADO DE LA MATRIZ");
system("color 1e");

gotoxy(15,3); cout<<"LLENADO DE LA MATRIZ";
gotoxy(10,4); cout<<subraya;

//GENERA LAS LÍNEAS QUE DELIMITAN LOS ELEMENTOS DE LA MATRIZ
for(i=0;i<=f+1;i++)
{gotoxy(4,i+6); cout<<"|";
gotoxy(7*(c-1)+12,i+6); cout<<"|";
}

gotoxy(5,5); cout<<"_";
gotoxy(5,f+7); cout<<"_";
gotoxy(7*(c-1)+11,5); cout<<"_";
gotoxy(7*(c-1)+11,f+7); cout<<"_";


//LECTURA DE LOS ELEMENTOS DE LA MATRIZ
for(i=0;i<=f-1;i++)
for(j=0;j<=c-1;j++)
{
gotoxy(j*7+8,i+7); cin>>M[i][j];
}
}



//MENÚ PRINCIPAL

void Opc()
{
char resp;
system("title OPCIONES DEL PROGRAMA");
clrscr();
system("color 1e");
gotoxy(15,3); cout<<"MENU DE OPCIONES";
gotoxy(10,4); cout<<subraya;
Sleep(500); gotoxy(5,6); cout<<"A) Mostrar la matriz almacenada ";
Sleep(500); gotoxy(5,8); cout<<"B) Calcular la traza ";
Sleep(500); gotoxy(5,10); cout<<"C) Calcular el determinante ";
Sleep(500); gotoxy(5,12); cout<<"D) SALIR"; Sleep(500);
do{
gotoxy(5,16); clreol(); system("color 1e"); cout<<"Ingrese opcion ===> "; cin>>resp;
if(resp!='A' && resp!='B' && resp!='C' && resp!='D' && resp!='a' && resp!='b' && resp!='c' && resp!='d')
{gotoxy(14,14); textcolor(LIGHTRED); cprintf(" :( Opcion no valida");
}
else
{gotoxy(5,14); clreol(); system("color 1e");
}
}while(resp!='A' && resp!='B' && resp!='C' && resp!='D' && resp!='a' && resp!='b' && resp!='c' && resp!='d');

if(resp=='a') resp='A';
if(resp=='b') resp='B';
if(resp=='c') resp='C';
if(resp=='d') resp='D';
getchar();
RealizaOp(resp);
}

// FUNCION QUE REALIZA LA OPCION ELEGIDA EN EL MENU DE OPCIONES
void RealizaOp(char r)
{
switch(r)
{
case'A':
MostrarM(A);
break;
case'B':
{

}
break;

case'C':
{

}
break;

case'D':
{
}
break;
}

}


// FUNCION QUE MUESTRA UNA MATRIZ

void MostrarM(float M[10][10])
{
int i,j;
clrscr();
system("color 1e");
system("title MOSTRAR LA MATRIZ");

gotoxy(15,3); cout<<"MOSTRANDO LA LA MATRIZ";
gotoxy(10,4); cout<<subraya;

//GENERA LAS LÍNEAS QUE DELIMITAN LOS ELEMENTOS DE LA MATRIZ

for(i=0;i<=f+1;i++)
{gotoxy(4,i+6); cout<<"|";
gotoxy(7*(c-1)+12,i+6); cout<<"|";
}

gotoxy(5,5); cout<<"_";
gotoxy(5,f+7); cout<<"_";
gotoxy(7*(c-1)+11,5); cout<<"_";
gotoxy(7*(c-1)+11,f+7); cout<<"_";


//MOSTRANDO LOS ELEMENTOS DE LA MATRIZ

for(i=0;i<=f-1;i++)
for(j=0;j<=c-1;j++)
{
gotoxy(j*7+8,i+7); cout<<M[i][j];
}

}



//4. PROGRAMA PRINCIPAL ////////////////////////////////////////…


int main(void)
{
Rango();
LlenarM(A);
Opc();






return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Posdata

Publicado por Luis Alberto Guisado Mena (4 intervenciones) el 04/06/2011 04:47:34
Sospecho que el error es en la función MostrarM()

Aún me confundo mucho en lo que respecta a las variables locales, globales, paso de parámetros por valor o referencia.

Por ejemplo:

Si en mi programa principal tengo como variable global: int a;

Entonces, ¿Desde cualquier función puedo modificarla sin necesidad de pasarla por referencia? O Necesito pasarla por referencia a la función.

Osea:

Si mi función definida es:

void función1(int x)
{
x=x*x;
}

Y mi programa principal es:

int main(void)
{
función1(a);
return 0;
}


O basta con que haga:

void función1()
{
a=a*a;
}

Y mi programa principal es:

int main(void)
{
función1();
return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

AYUDA error de compilación en C++

Publicado por Luis Alberto Guisado Mena (4 intervenciones) el 27/12/2014 04:35:18
Hola Luis, soy tú :D pero 3 años en el futuro xD . Te diré cual es tu error. Tu error está en el prototipo de la función que se encarga de mostrar la matriz, la función llamada MostrarM. Si te das cuenta, en el prototipo de esa función estás declarando que ésta tiene un argumento de tipo float cuando deberías de especificar que se trata de una matriz de dos dimensiones de la siguiente forma:

void MostrarM(float [][10]);

Eso sería todo :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar