Thread: missing ')' before constant

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    10

    missing ')' before constant

    When I debug the definitions for all my functions give me missing ')' before constant, and missing ';' before constant. It all looks good to me, just wondering what would make it give me that error and how I might be able to fix it?
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <cmath>
    #define size 50
    
    using namespace std;
    
    void headings(ofstream &outFile);
    float readData(ifstream &inFile, float customer[], float balance[], float);
    void sort(ifstream &inFile, float balance[], float);
    void printResults(ofstream &outFile, ifstream &inFile, float customer[], float balance[], float);
    
    int main()
    {
    	//declare variables
    	float customer[size];
    	float balance[size];
    	
    	//open files
    	ifstream inFile;
    	ofstream outFile;
    	inFile.open("prog7.txt");
    	outFile.open("prog7.out");
    
    	// funtion to print headings
    	headings(outFile);
    	
    	// read from file
    	readData(inFile, customer, balance, size);
    	
    	// function to sort in descending order
    	sort(inFile, balance, size);
    
    	// function to print results
    	printResults(outFile, inFile, customer, balance, size); 
    
    	// close files
    	outFile.close();
    	inFile.close();
    	return 0;
    }
    	void headings(ofstream &outFile)
    	{
    		outFile <<setw(10)<< "Customer ID"
    				<<setw(10)<< "Balance"
    				<<endl;
    	}
    	float readData(ifstream &inFile, float customer[], float balance[], float size) 
    	{
    		for (int i = 0; i <size; i++) 
    		{
    			if (!(inFile>> customer[i] >>balance[i]))
    		}
    			break;
    				return i;
    	}
    	void sort(ifstream &inFile, float balance[], float size)
    	{
    		float temp = 0;			
            for(int j=1; j< size; j++)
    		{
    			for(int i=0; i< size-1; i++)
    			{
    				if(balance[i] > balance[i+1])
    				{
    					temp=balance[i];
    					balance[i]=balance[i+1];
    					balance[i+1]=temp;
    				}
    			}
    		}
    	}
    	void printResults(ofstream &outFile, ifstream &inFile, float customer[], float balance[], float size)
    	{
    		outFile << setprecision(2) << fixed << showpoint;
    		for (int i=0; i < size; i++)
    		outFile <<setw(10)<< customer[i]
    				<<setw(10)<< balance[i]
    				<<endl << endl;
    	}

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I got some errors that look very different from what you are describing. The ones you describe simply mean that you are missing one of those characters when there should be one, and that it may cause some ambiguity in your code. However, I would recommend that you post the specific error messages you are getting, the line numbers, etc... and all that other good stuff.

    Before doing that though, I recommend you proofread your code. You have a break statement in there for no apparent reason - wrong location, perhaps?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    you have a conflict due to a macro:
    Code:
    #define size 50
    void sort(ifstream &inFile, float balance[], float size)
    becomes
    Code:
    void sort(ifstream &inFile, float balance[], float 50)
    The convention is for all macros to be all capital letters ie: SIZE

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Also, you might want to simply make it a constant instead of a macro (it helps prevent errors such as these). Convention is also all upper-case for constants as well.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79
    Hi Barfchunk. I see that you have an error here:
    Code:
    	float readData(ifstream &inFile, float customer[], float balance[], float size) 
    	{
    		for (int i = 0; i <size; i++) 
    		{
    			if (!(inFile>> customer[i] >>balance[i]))
    		}
    			break;
    				return i;
    	}
    ...after fixing this:
    Code:
    using namespace std;
    
    const int SIZE = 50; // meets the standard!
    
    void headings(ofstream &outFile);
    /*...*/
    I have fixed it for you:
    Code:
    float readData(ifstream &inFile, float customer[], float balance[], float size) 
    	{
    		for (int i = 0; i <size; i++) 
    		{
    			if (!(inFile>> customer[i] >>balance[i]))
    			    break;
    			return i;
    		}
    	}
    ...unless this isn't the logic that you really want. Anyway, it now compiles error-free.

    Like I said before, it's very important to be careful. Compilers will find such errors and alert you to them. Correcting them will put you closer to getting your mission accomplished.

    Best,

    Steve
    Last edited by smitsky; 12-05-2004 at 10:49 PM. Reason: Correction to previous posting

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    10
    Thanks for all the help guys, got everything to work perfect now... these boards really help with the learning process.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM