Hello, I am doing an assignment on programming and I have run into 21 errors. The program is not complete, but I just wanted to test it out to make the the output works the way I want it to. The object of the program is to read an inputfile, store info into 4 arrays that each hold a category of values, then write the info to an outputfile.. Employee Ids, hours, payRate, and wages are the arrays. I have searched online for these errors and I haven't found a solution, I do not know what I am doing wrong! Please help! here are the errors I am getting:
1>------ Build started: Project: Pro8, Configuration: Debug Win32 ------
1>Compiling...
1>Pro8.cpp
error C2146: syntax error : missing ';' before identifier 'ofstream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'ifstream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2228: left of '.open' must have class/struct/union
1> type is 'int'
error C2059: syntax error : ']'
error C2143: syntax error : missing ';' before '{'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2297: '>>' : illegal, right operand has type 'double'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2297: '>>' : illegal, right operand has type 'double'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2228: left of '.open' must have class/struct/union
1> type is 'int'
error C2297: '<<' : illegal, right operand has type 'const char [53]'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
error C2297: '<<' : illegal, right operand has type 'const char [45]'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>Proj8 - 21 error(s), 6 warning(s)
1>------ Build started: Project: Pro8, Configuration: Debug Win32 ------
1>Compiling...
1>Pro8.cpp
error C2146: syntax error : missing ';' before identifier 'ofstream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2146: syntax error : missing ';' before identifier 'ifstream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2228: left of '.open' must have class/struct/union
1> type is 'int'
error C2059: syntax error : ']'
error C2143: syntax error : missing ';' before '{'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2297: '>>' : illegal, right operand has type 'double'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2297: '>>' : illegal, right operand has type 'double'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2228: left of '.open' must have class/struct/union
1> type is 'int'
error C2297: '<<' : illegal, right operand has type 'const char [53]'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
warning C4552: '<<' : operator has no effect; expected operator with side-effect
error C2297: '<<' : illegal, right operand has type 'double'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
error C2297: '<<' : illegal, right operand has type 'const char [45]'
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>Proj8 - 21 error(s), 6 warning(s)
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <ostream>
using namespace std;
outputFile ofstream;
inputFile ifstream;
const long int ARRAY_SIZE = 20;
long int empId[ARRAY_SIZE];
double hours[ARRAY_SIZE];
double payRate[ARRAY_SIZE];
double wages[ARRAY_SIZE];
int main()
{
cout << setprecision(2) << fixed << showpoint;
cout << "\tPAYROLL PROCESSING" << endl << endl;
char fileName[50];
cout << "Enter the name of the input file ";
cin >> fileName;
inputFile.open(fileName);
while (empId[] != -1)
{
for(int count = 0; count < ARRAY_SIZE; count++)
{
inputFile >> empId[count];
}
for(int count = 0; count < ARRAY_SIZE; count++)
{
inputFile >> hours[count];
}
for(int count = 0; count < ARRAY_SIZE; count++)
{
inputFile >> payRate[count];
}
}
char fileName[50];
cout << "\nEnter the name of the output file ";
cin >> fileName;
outputFile.open(fileName);
char empnum[50];
cout << "\nEnter an employee number for your search: ";
cin >> empnum;
outputFile << "Employee number\t\tHours Worked\tPayrate per Hour\tWages" << endl;
for(int count = 0; count < ARRAY_SIZE; count++)
{
wages[count] = hours[count] * payRate[count];
outputFile << empId[count];
outputFile << hours[count];
outputFile << payRate[count];
outputFile << wages[count] << endl;
}
outputFile << "Employees sorted on identification numbers: " << endl << endl;
}
Last edited: