Getting error when compiling code

I'm getting the following error when I compile my code. Not sure what i need to do, but I think it ties in with an improperly coded control loop. Any thoughts?

piecework1a.cpp
\\TSCLIENT\C\Users\Bryan.Hendricks\Downloads\fwcos50290(1)\piecework1a.cpp(91) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90


//COS 502-90

//October 28,2012

//This program uses a sentinel-controlled loop that transforms input to output.



#include <iostream>

#include <fstream>

#include <iomanip>  //output formatting

#include <string>   //string variables

using namespace std;



int main()

{



	double pieces;			//number of pieces made

	double rate1, rate2, rate3, rate4;			//amout paid per amount produced

	double pay;				//amount earned 

	string name;			//name of worker

	ifstream inFile;

	ofstream outFile;



	//***********input statements****************************

	inFile.open("Piecework1.txt");	//opens the input text file

	outFile.open("piecework1.out");  //opens the output text file

	outFile << setprecision(2) << showpoint;

	outFile << name << setw(6) << "Pieces" << setw(12) << "Pay" << endl;

	outFile << "_____" << setw(6) << "_____" << setw(12) << "_____" << endl;

	getline(inFile, name, '*');			//priming read

	inFile >> pieces >> pay;	// ,,

	while (name != "End of File")			//while condition test

	{										//begining of loop
		{if	(pieces>=1 && pieces<=199)
			rate1=.50;
			pay = pieces * rate1;

		if (pieces>=200 && pieces<=399)
			rate2=.55;
			pay = pieces * rate2;

		if (pieces>=400 && pieces<=599)
			rate3=.60;
			pay = pieces * rate3;

		if (pieces>=600)
			rate=4.65;
			pay = pieces * rate4;

		getline(inFile, name, '*');		//get next name

		inFile >> pieces;				//get next pieces

	}									//end of loop

	inFile.close();

	outFile.close();

	return 0;

}
Last edited on
What is the purpose of this?

If you're looking for help state the problem that you're having and error codes that come with it.

If you're looking for input on the program, state that at the beginning of the post.

All you've done is posted a bunch of code that we don't know what to do with
Remove the '{' on line 62. The compiler sees 3 '{'s and only 2 '}'s so it does not expect the file to be done yet.
Thanks, removed bracket, but now getting a new error on line 37 when I try to build the file.

Compiling...
Piecework1.cpp
C:\Documents and Settings\XPMUser\Desktop\Piecework1\Piecework1.cpp(37) : error C2146: syntax error : missing ';' before identifier 'string'
Error executing cl.exe.

Piecework1.exe - 1 error(s), 0 warning(s)
I don't see what would cause that error; can you post your new code? Also you have another problem on line 75, rate = 4.65 should be rate4 = .65
You also have a logic error with your if statements.
Since you have no braces following your if statements, only the first statement is going to be executed if thre condition is true. The second statement (calculating pay) will be executed unconditionally. The compiler does not pay attention to you indentation.

This is going to give you unpredictable results. Regardless of how many pieces were read, you're going to calculate pay using rate4. Now if you haven't encountered any pieces > 600, rate4 is going to be uninitialized.

Also at line 57, you read a value from the file into pay, but then proceed to overwrite that value. What's the purpose of reading that value from the file?


So I've completely rewritten the code, and here's what I've come up with.

but I'm still gettting errors. Also, before I post the code, here is a copy of the input file as one. The name of the file is piecework1.txt

JOHNNY BEGOOD* 265 .55
SALLY GREAT* 650 .65
SAM KLUTZ* 177 .50
PETE PRECISE* 400 .60
FANNIE FANTASTIC* 399 .55
MORRIE MELLOW* 200 .55
End of File* 9999 9999

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//

//COS 502-90

//Nov 7,2012

//This program uses a sentinel-controlled loop that transforms input to output.



#include <iostream>

#include <fstream>

#include <iomanip>  //output formatting

#include <string>   //string variables

using namespace std;



int main()

{



	double pieces, rate, pay;	//number of pieces made, rate of pay, amount of pay

	string name;				//name of worker

	ifstream inFile;			//holds name, pieces and rate

	ofstream outFile;			//holds the name piecs and pay


	//***********input statements****************************

	inFile.open("Piecework1.txt");	//opens the input text file

	outFile.open("piecework1.out");  //opens the output text file

	outFile << setprecision(2) << showpoint;

	outFile << name << setw(6) << "pieces" << setw(12) << "pay" << endl;

	outFile << "_____" << setw(6) << "_____" << setw(12) << "_____" << endl;

	getline(inFile, name, '*');				//priming read

	inFile >> pieces >> rate;		// ,,

	while (name != "End of File")			//while condition test

	{										//begining of loop

		pay = pieces * rate;

		getline(inFile, name, '*');		//get next name

		inFile >> pieces;				//get next pieces

		inFile.ignore (80,'\n');
	]


	inFile.close();

	outFile.close();

	return 0;

}


The errors I get when I run the file are as follows. Honestly I don't even understand the errors because I'm not using any if/else statements, either I need to, or I'm missing something (Which is probably the case). Where am I going wrong?

BTW, here are the errors.

1>------ Build started: Project: Piecework1, Configuration: Debug Win32 ------
1>Compiling...
1>Piecework1.cpp
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(64) : error C2181: illegal else without matching if
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(64) : error C2059: syntax error : ')'
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(65) : error C2146: syntax error : missing ';' before identifier 'rate'
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(68) : error C2181: illegal else without matching if
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(69) : error C2146: syntax error : missing ';' before identifier 'rate'
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(72) : error C2181: illegal else without matching if
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(73) : error C2146: syntax error : missing ';' before identifier 'rate'
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(74) : error C2065: 'rate4' : undeclared identifier
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(76) : error C2181: illegal else without matching if
1>c:\users\bryan\documents\visual studio 2008\projects\piecework1\piecework1\piecework1.cpp(78) : error C2146: syntax error : missing ';' before identifier 'getline'
1>Build log was saved at "file://c:\Users\Bryan\Documents\Visual Studio 2008\Projects\Piecework1\Piecework1\Debug\BuildLog.htm"
1>Piecework1 - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Last edited on

On your line 65, you misplaced a square bracket, replace with a curly brace and that should get you past that error.

Last edited on
Line 65 has a square bracket ']' instead of a curly brace '}'.

If you IDE /editor doesn't highlight the syntax for you, then I recommend trying a different editor, at least as a way of getting a second opinion on the code,

I can recommend Notepad++ for syntax highlighting and matching of opening / closing brackets.

Also, if you find it hard to distinguish these characters, configure the editor to use a different font - some are designed with programmers in mind.

Topic archived. No new replies allowed.