Finished program to find determinant of matrix: wont compile?

This is a discussion on Finished program to find determinant of matrix: wont compile? within the C Programming forums, part of the General Programming Boards category; Hello, i have written this program, it is close to being finished... it should compile i think but im getting ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    13

    Exclamation Finished program to find determinant of matrix: wont compile?

    Hello, i have written this program, it is close to being finished... it should compile i think but im getting the following errors (lines might not match up)

    Code:
    ass.c:42: error: 'minordet' undeclared (first use in this function)
    ass.c:42: error: (Each undeclared identifier is reported only once
    ass.c:42: error: for each function it appears in.)
    ass.c:42: error: too few arguments to function 'MinorDeterminant'
    ass.c: At top level:
    ass.c:55: error: conflicting types for 'MinorDeterminant'
    ass.c:14: note: previous declaration of 'MinorDeterminant' was here
    Here is the program:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    float MinorDeterminant(float minor[3][3], int i, int j);
    
    int main(int argc, char* argv[])
    {
        FILE         *input;
        int           i, j;  
        float         matrix[3][3], determinant;
        const char    inp_fn[]="matrix.dat";
    	
        /* Open files */
        input = fopen(inp_fn, "r");
        /* Check the pointers to files are not NULL, also check matrix has correct number of elements... not done yet */
        if( (input != (FILE*) NULL) )
        {
          {	
    	printf("| ");
    		for (i = 0; i < 3; i++)
    			for (j = 0; j < 3; j++) 
    			{
    				fscanf(input, "%f", &matrix[i][j]);
    				printf("%.4f  ", matrix[i][j]);
    				if (j == 2 && i < 2) 
    				printf("| \n |");
    			}			
    	printf("|\n");		
    	}		
        for(i=0, j=0; j<=2; j++)
    	{
    	determinant += (pow(-1, j)) * (matrix[i][j]) * MinorDeterminant(minordet);
    	printf("Determinant = %f", determinant);
    	}
    	fclose(input);
    	return(0);
    	}
     else
       {
        printf("*** Could not open input file, or there are not 9 elements in the matrix ***\n");
    	exit(EXIT_FAILURE);
       }
    }  
    
    float MinorDeterminant(float matrix[3][3])
    {
    float minordet;
    int i, j;
    
    if (i==0 && j==0)
    
    minordet = (matrix[1][1] * matrix[2][2]) - (matrix[2][1] * matrix[1][2]);
    
    else if (i==0 && j==1)
    
    minordet = (matrix[1][0] * matrix[2][2]) - (matrix[2][0] * matrix[1][2]);
    
    else if (i==0 && j==2)
    
    minordet = (matrix[1][0] * matrix[2][1]) - (matrix[2][0] * matrix[1][1]);
    
    return(minordet);
    }
    Please help me fix the errors, thank you!

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Braces problem most likely. Any particular reason why you open 2 after the if(input != NULL) ?

    Your indentation is horrible which is why you can't see what is going on
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    Your function prototype says
    Code:
    float MinorDeterminant(float minor[3][3], int i, int j);
    But when you do your function definition: you wrote:
    Code:
    float MinorDeterminant(float matrix[3][3])
    In
    Code:
    determinant += (pow(-1, j)) * (matrix[i][j]) * MinorDeterminant(minordet);
    "minordet" is never declared, i think you meant "matrix" because you read your file into "matrix".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Matrix
    By alex 2010 in forum C++ Programming
    Replies: 0
    Last Post: 06-24-2010, 09:40 AM
  2. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. How To Embed Data In Program While Compile?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2002, 10:14 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21