Results 1 to 15 of 15

Thread: Why do I get these warnings in GCC 3.3 and yet compiles fine on vs.net.:Resolved:.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Why do I get these warnings in GCC 3.3 and yet compiles fine on vs.net.:Resolved:.

    GCC 3.3 compiler in a unix environment I get these warnings
    Code:
    homework5.cpp: In function `void isMagic(int*, int (*)[4], int, int)':
    homework5.cpp:123: warning: ISO C++ forbids declaration of `magicCounter' with 
       no type
    homework5.cpp:179: warning: name lookup of `row' changed for new ISO `for' 
       scoping
    homework5.cpp:135: warning:   using obsolete binding at `row'
    The reason i'm upset, is because my programming teacher is giving me a 55/100 on this homework assignment because he says, it doesn't compile. Thats bull**** because I just tested it and I just get warnings, not errors. I just need somthing to say to him to show him that, no i'm right, he's wrong, i shouldn't have got 55% on this homework becuase I get 3 warnings on a GCC compiler, and no warnings in .net. He also said, you can use any compiler you want as long as it uses the standard. Here's the program:
    Code:
    //File: homework5.cpp
    //Written By: Cory Sanchez
    /*Purpose:
    The  generatEntries function creates 
    a one-dimensional array of n2 elements 
    ordered as the terms of an arithmetic 
    sequence. The function also outputs the arithmetic 
    sequence.
    The program will then put the one-dimensional matrix
    into a two-dimensional matrix and reverse the diagnoals.
    A "magic number" is then generated, the program will then
    compare the magic number with the sum of each row and column
    if they are equal, the matrix has a "magic number".
    */
    
    #include <iostream>
    using namespace std;
    
    
    void generateEntries(int matrix[], int size);
    void createMatrix(int matrix[], int newMatrix[][4], int );
    void reverseDiagonals(int newMatrix[][4], int row);
    void printMatrix(int newMatrix[][4],int size);
    void printMatrix(int matrix[], int size);
    void isMagic(int matrix[], int newMatrix[][4], int size1, int size2);
    
    int main()
    {
    	const int ROW = 4;
    	const int COL = 4;
    	int SIZE = 16;						//number of rows * columns == size of whole matrix
    
    	int matrix[ROW*COL];
    	int newMatrix[ROW][COL];
    	generateEntries(matrix,SIZE);
    	createMatrix(matrix,newMatrix,ROW);
    	printMatrix(newMatrix,ROW);
    	reverseDiagonals(newMatrix,ROW);
    	printMatrix(newMatrix,ROW);
    	isMagic(matrix,newMatrix,SIZE,ROW);
    	return 0;
    }
    
    void generateEntries(int matrix[], int size)
    {
    	int first, difference;
    	cout <<"Enter two numbers: ";
    	cin >> first >> difference;
    	
    	matrix[0] = first;
    	for(int i = 1; i < size; i++)
    	{
    		matrix[i] = difference+matrix[i-1];
    	}
    
    	printMatrix(matrix,size);
    	
    }
    
    void createMatrix(int matrix[], int newMatrix[][4], int row)
    {
    	static int counter = 0;		//to iterate through a of matrix[i]
    	for(int i = 0; i < row; i++)
    	{
    		for(int j = 0; j < row; j++, counter++)
    		{
    			newMatrix[i][j] = matrix[counter];
    		}
    	}
    }
    
    void reverseDiagonals(int newMatrix[][4], int row)
    {
    	int temp;
    
    	for(int i = 0; i < row/2; i++)
    	{
    		temp = newMatrix[i][i];
    		newMatrix[i][i] = newMatrix[row-1-i][row-1-i];
    		newMatrix[row-1-i][row-1-i] = temp;
    	}
    	for(int j = 0; j < row/2; j++)
    	{
    		temp = newMatrix[j][row-1-j];
    		newMatrix[j][row-1-j] = newMatrix[row-1-j][j];
    		newMatrix[row-1-j][j] = temp;
    	}
    }
    
    void printMatrix(int newMatrix[][4],int size)
    {
    	for(int i = 0; i < size; i++)
    		{
    		for(int j = 0; j < size; j++)
    			{
    			if(j%4 == 0)
    				{
    				cout << endl;
    				}
    				cout << newMatrix[i][j]<<" ";
    			}
    		}
    		cout << endl;
    }
    
    void printMatrix(int matrix[], int size)
    {
    	for(int i =0; i < size; i++)
    	{
    		cout <<matrix[i]<<" ";
    	}
    	cout << endl;
    }
    
    void isMagic(int matrix[], int newMatrix[][4], int size1, int size2)
    {
    	int sum = 0;				//holds the sum of the 1-dim array
    	int colSum = 0;
    	int rowSum = 0;
    	int mainDSum = 0;
    	int oppDSum = 0;
    	int magicNum = 0;
    	static magicCounter = 0;	//keeps track of the magic rows/columns
    	
    	//generating the magic number
    	for(int i = 0; i < size1; i++)
    	{
    		sum += matrix[i];
    	}
    	
    	magicNum = sum/size2;			//sum divided by # of rows
    	
    	cout <<"magic number: " << magicNum << endl;
    	//adding up rows
    	for(int row = 0; row < size2; row++)
    	{
    		rowSum = 0;
    		for(int col = 0; col < size2; col++)
    		{
    			rowSum = rowSum + newMatrix[row][col];
    		}
    		
    		if(rowSum == magicNum)			
    		{
    			magicCounter++;
    		}
    	}
    	
    	//adding up cols
    	for(int col = 0; col < size2; col++)
    	{
    		colSum = 0;
    		for(int row = 0; row < size2; row++)
    		{
    			colSum = colSum + newMatrix[row][col];
    		}
    		
    		if(colSum == magicNum)
    		{
    			magicCounter++;
    		}
    	}
    
    	//add up main diagnoal
    	for(int i = 0; i < size2/2; i++)
    	{
    		mainDSum = mainDSum + newMatrix[i][i];
    		mainDSum += newMatrix[size2-1-i][size2-1-i];
    	}
    	if(mainDSum == magicNum)
    	{
    		magicCounter++;
    	}
    
    	//add up opposite diagnoal
    	for(int i = 0; i < size2/2; i++)
    	{
    		oppDSum += newMatrix[i][size2-1-i];
    		oppDSum += newMatrix[row-1-i][i];
    	}
    	if(oppDSum == magicNum)
    	{
    		magicCounter++;
    	}
    	
    	//check if matrix has a magic number
    	if(magicCounter == (2 * size2+2))
    	{
    		cout <<"This matrix has a magic number!\n";
    	}
    	else
    	{
    		cout <<"This matrix has no magic number!\n";
    	}
    	
    }
    Last edited by voidflux; Dec 12th, 2003 at 01:26 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width