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 ==========