SYNTAX ERROR

Error 7 error C2059: syntax error : '}'

Page 1 of 1

1 Replies - 1692 Views - Last Post: 04 April 2009 - 12:11 PM Rate Topic: -----

#1 roncka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 02-March 09

SYNTAX ERROR

Post icon  Posted 04 April 2009 - 12:03 PM

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>


using namespace std;

const int MAX_trSYM = 8;
const int MAX_cmpNAME = 30;
const int MAX_fNAME = 100;
const int Size = 15;


int ReadStkData(fstream&, char [][9], char [][31], int [], float [], float [], int);
void SortStkData(char [][9], char [][31], int [], float [], float [], int);
void WriteReport(ofstream&, char [][9], char [][31], int [], float [], float [], int);


int main()
{
	int number = 0;
	//To declare local variables
	char filein[MAX_fNAME+1], fileout[MAX_fNAME + 1];
	char trSym[Size][9], cmpName[Size][31];
	int numShrs[Size];
	float pPrc[Size], cPrc[Size]; 
	int count = 0;

	fstream inFile;
	ofstream outFile;

	cout << "Please enter output fileneme less than "
		<< MAX_fNAME << " characters: ";
	cin.getline(filein, MAX_fNAME+1);
	inFile.open(filein, ios::in);
	if (inFile.fail())
	{
		cout << "Could not open input data file" 
			<< filein << "for input" << endl;
		return 1;
	}

	cout << "Please enter input fileneme less than "
		<< MAX_fNAME << " characters: ";
	cin.getline(fileout, MAX_fNAME+1);
	outFile.open(fileout, ios::out);
	if (outFile.fail())
	{
		cout << "Could not open output data file" 
			<< fileout << "for input" << endl;
		return 1;
	}

	

	number = ReadStkData(inFile, trSym, cmpName, numShrs, pPrc, cPrc, Size);
	SortStkData(trSym, cmpName, numShrs, pPrc, cPrc, number);
	WriteReport(outFile, trSym, cmpName, numShrs, pPrc, cPrc, number);
		
	inFile.close();
	return 0;
}


int ReadStkData(fstream& ifile, char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)
{
	
	//local variables
	int count = 0;
	cout.setf(ios::fixed,ios::floatfield);
	cout.precision(2);

	//read values until the end file is reached or max number of elements is read
	while(!ifile.eof() && count < Size)
	{
		ifile.get(trSym[count], MAX_trSYM+1);
		ifile.get(cmpName[count], MAX_cmpNAME+1);
		ifile >> numShrs[count];
		ifile >> pPrc[count];
		ifile >> cPrc[count];

		ifile.ignore();
		cout << trSym[count] << cmpName[count] << setw(6) << right << numShrs[count] << "  " << setw(5) << pPrc[count] << "  " << setw(5) << cPrc[count] << endl;
		count++;
		
	}
	
	return count;

	
}


void WriteReport(ofstream& ofile, char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)

{
	// local variables
	cin.setf(ios::fixed,ios::floatfield); 
	cin.precision(2);
	//float AG();
	//double TaxOwed;
	//string gain = "GAIN";
	//string loss = "LOSS";
	//string status;


	for(int count = 0; count < Size; count++)
	{
		
	//*******************************************************************************
	//	AG = (pPrc[count] * numShrs[count]) - (pPrc[count] * numShrs[count]);	   *
	//	TaxOwed = AG * 0.15;														*
	//		if (AG[count] > 0)														*
	//		status = gain;															*
	//		else																	*
	//		status = loss;															*
	//*******************************************************************************

	ofile << trSym[count] << cmpName[count] << setw(6) << right << numShrs[count] << "  " << setw(5) << pPrc[count] << "  " << setw(5) << cPrc[count] <<  endl;
	
	
	}
	
			
	return;
}


void SortStkData(char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)

{  
	bool swap;
	char tempSym[9]; 
	char tempName[31];
	int tempShrs;
	float tempPP;
	float tempCP;


	do
	{
		swap = false;
		for (int count = 0; count < (Size - 1); count++)
		{
			if (strcmp(trSym[count], trSym[count + 1]) > 0)
			{
				strcpy(tempSym, trSym[count]);
				strcpy(trSym[count], trSym[count + 1]);
				strcpy(trSym[count + 1], tempSym);

				strcpy(tempName, cmpName[count]);
				strcpy(cmpName[count], cmpName[count + 1]);
				strcpy(cmpName[count + 1], tempName);

				tempShrs = numShrs[count];
				numShrs[count] = numShrs[count + 1];
				numShrs[count + 1] = tempShrs;

				tempPP = pPrc[count];
				pPrc[count] = pPrc[count + 1];
				pPrc[count + 1] = tempPP;

				tempCP = cPrc[count];
				cPrc[count] = cPrc[count + 1];
				cPrc[count + 1] = tempCP;

				swap = true;
			}
	
		}	while (swap);
	}
} 

FILE TO READ FROM IS ATTACHED.
THE ERROR I GET IS :
Error 7 error C2059: syntax error : '}'

Attached File  stock.txt (425bytes)
Number of downloads: 77

Is This A Good Question/Topic? 0
  • +

Replies To: SYNTAX ERROR

#2 roncka   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 02-March 09

Re: SYNTAX ERROR

Posted 04 April 2009 - 12:11 PM

View Postroncka, on 4 Apr, 2009 - 11:03 AM, said:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>


using namespace std;

const int MAX_trSYM = 8;
const int MAX_cmpNAME = 30;
const int MAX_fNAME = 100;
const int Size = 15;


int ReadStkData(fstream&, char [][9], char [][31], int [], float [], float [], int);
void SortStkData(char [][9], char [][31], int [], float [], float [], int);
void WriteReport(ofstream&, char [][9], char [][31], int [], float [], float [], int);


int main()
{
	int number = 0;
	//To declare local variables
	char filein[MAX_fNAME+1], fileout[MAX_fNAME + 1];
	char trSym[Size][9], cmpName[Size][31];
	int numShrs[Size];
	float pPrc[Size], cPrc[Size]; 
	int count = 0;

	fstream inFile;
	ofstream outFile;

	cout << "Please enter output fileneme less than "
		<< MAX_fNAME << " characters: ";
	cin.getline(filein, MAX_fNAME+1);
	inFile.open(filein, ios::in);
	if (inFile.fail())
	{
		cout << "Could not open input data file" 
			<< filein << "for input" << endl;
		return 1;
	}

	cout << "Please enter input fileneme less than "
		<< MAX_fNAME << " characters: ";
	cin.getline(fileout, MAX_fNAME+1);
	outFile.open(fileout, ios::out);
	if (outFile.fail())
	{
		cout << "Could not open output data file" 
			<< fileout << "for input" << endl;
		return 1;
	}

	

	number = ReadStkData(inFile, trSym, cmpName, numShrs, pPrc, cPrc, Size);
	SortStkData(trSym, cmpName, numShrs, pPrc, cPrc, number);
	WriteReport(outFile, trSym, cmpName, numShrs, pPrc, cPrc, number);
		
	inFile.close();
	return 0;
}


int ReadStkData(fstream& ifile, char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)
{
	
	//local variables
	int count = 0;
	cout.setf(ios::fixed,ios::floatfield);
	cout.precision(2);

	//read values until the end file is reached or max number of elements is read
	while(!ifile.eof() && count < Size)
	{
		ifile.get(trSym[count], MAX_trSYM+1);
		ifile.get(cmpName[count], MAX_cmpNAME+1);
		ifile >> numShrs[count];
		ifile >> pPrc[count];
		ifile >> cPrc[count];

		ifile.ignore();
		cout << trSym[count] << cmpName[count] << setw(6) << right << numShrs[count] << "  " << setw(5) << pPrc[count] << "  " << setw(5) << cPrc[count] << endl;
		count++;
		
	}
	
	return count;

	
}


void WriteReport(ofstream& ofile, char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)

{
	// local variables
	cin.setf(ios::fixed,ios::floatfield); 
	cin.precision(2);
	//float AG();
	//double TaxOwed;
	//string gain = "GAIN";
	//string loss = "LOSS";
	//string status;


	for(int count = 0; count < Size; count++)
	{
		
	//*******************************************************************************
	//	AG = (pPrc[count] * numShrs[count]) - (pPrc[count] * numShrs[count]);	   *
	//	TaxOwed = AG * 0.15;														*
	//		if (AG[count] > 0)														*
	//		status = gain;															*
	//		else																	*
	//		status = loss;															*
	//*******************************************************************************

	ofile << trSym[count] << cmpName[count] << setw(6) << right << numShrs[count] << "  " << setw(5) << pPrc[count] << "  " << setw(5) << cPrc[count] <<  endl;
	
	
	}
	
			
	return;
}


void SortStkData(char trSym[][9], char cmpName[][31], int numShrs[], float pPrc[], float cPrc[], int Size)

{  
	bool swap;
	char tempSym[9]; 
	char tempName[31];
	int tempShrs;
	float tempPP;
	float tempCP;


	do
	{
		swap = false;
		for (int count = 0; count < (Size - 1); count++)
		{
			if (strcmp(trSym[count], trSym[count + 1]) > 0)
			{
				strcpy(tempSym, trSym[count]);
				strcpy(trSym[count], trSym[count + 1]);
				strcpy(trSym[count + 1], tempSym);

				strcpy(tempName, cmpName[count]);
				strcpy(cmpName[count], cmpName[count + 1]);
				strcpy(cmpName[count + 1], tempName);

				tempShrs = numShrs[count];
				numShrs[count] = numShrs[count + 1];
				numShrs[count + 1] = tempShrs;

				tempPP = pPrc[count];
				pPrc[count] = pPrc[count + 1];
				pPrc[count + 1] = tempPP;

				tempCP = cPrc[count];
				cPrc[count] = cPrc[count + 1];
				cPrc[count + 1] = tempCP;

				swap = true;
			}
	
		}	while (swap);
	}
} 

FILE TO READ FROM IS ATTACHED.
THE ERROR I GET IS :
Error 7 error C2059: syntax error : '}'

Attachment attachment



i figured it out.
the problem was the "while (swap);" should of been after the next '}'

		}	
	} while (swap);
	
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1