errors c2181 and c3867 :/

I have recently started to learn C++, so I expect there to be a couple stupid mistakesin my program . I'm supposed to write a program that opens a user-defined file, within that file there are a few lines each consisting of: a name, Social Security Number, birth year, employment start date, monthly salary and job title. My program is at first supposed to output all the information in that file, and then it is supposed to calculate the bonus of certain individuals (if they were born prior to 1982, or employed before 2008), and then the yearly salary of all the individuals, as well as adding the bonus to their salary (if they recieved one). The new information is also supposed to be shown in the program, as well as written out to a new file (called "ReportFile.txt"). However, when compiling my program I recieved two compilation errors: C3867 - 'func': function call missing argument list, and C2181 - illegal else without matching if. I don't exactly know where the errors are though--here is my input text file as well as the program code:


Text file:

John Smith 111111111111 1963 2008 4000 Secretary
Tasha Patov 222222222 1973 2010 3000 Marketing
Francie Oldon 3333333333 1983 2008 4000 Secretary
Tuyet Nguyen 4444444444 1993 2012 43750 Sales
Jan Won 55555555 1964 2008 5000 Manager
Julie Nabong 666666666 1989 2010 45000 Manager
Jack Burnside 777777777 1991 2008 2000 Payroll
Larry Zubun 888888888 1980 2010 1500 Manufacturing
Valla Eide 999999999 1948 1980 9000 President


Program Code:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#include <stdlib.h>
#include <iomanip>


int main ()

{



ifstream fin;
string fileName;
getline(fin,fileName);
string firstName, lastName;
int SSN, birthYear, empStart, mSalary;
string jobTitle;
float yBonus, ySalary, totalSalary;

ySalary *= 12;
yBonus = static_cast<float>(0.10) * (mSalary) * (12);
totalSalary = (ySalary += yBonus);



// open a file whose name is entered by the user
cout << "What file do you want to use for input? ";
getline(cin, fileName);
fin.open(fileName.c_str),
(ios::in|ios::ate, 0);




fin>>firstName>>lastName>>SSN>>birthYear>>empStart>>mSalary>>jobTitle;
while(!fin.eof());
{





if(birthYear <= 1982 || empStart <= 2008);
{

cout << jobTitle << " " << firstName << " " << lastName << " Salary: " << ySalary;
cout << " Bonus: " << "0.00" << " Social Security Number: " << SSN << " ";
cout << "Total yearly salary: " << ySalary << endl;}








else if(birthYear >= 1982 || empStart >=2008);
{
cout << jobTitle << " " << firstName << " " << lastName << " Salary: " << ySalary;
cout << " Bonus: " << "0.00" << " Social Security Number: " << SSN << " ";
cout << "Total yearly salary: " << ySalary << endl;



cout << setprecision(0);

fin.close();



std::ofstream file;
ofstream fout;
fout.open("ReportFile.txt");
std::ofstream str("ReportFile.txt");
ios::out | ios::app;
std::ios_base::app;


fout << jobTitle << " " << firstName << " " << lastName << " Salary: " << ySalary;
fout << " Bonus: " << "0.00" << " Social Security Number: " << SSN << " ";
fout << "Total yearly salary: " << ySalary << endl << endl;




fout.close();







return 0;



}
}
;}


First, please post your code using the code tags (found under the Format: section.)

After your while( ! fin.eof() ) you have a semicolon: remove it. There are probably other errors.

Please post your compiler's output tool.
You need to test your program thoroughly each step of the way.

1
2
3
ifstream fin;
string fileName;
getline(fin,fileName)


What file is your program currently getting input from?

// 111111111111

Pretty sure this is over the max for an integer variable, which will cause problems.

 
fin>>firstName>>lastName>>SSN>>birthYear>>empStart>>mSalary>>jobTitle;


I feel like this should be in your while statement. Also, this line of code doesn't take into account that fin >> somevariable is going to eat up the newline character.

std::ofstream file;

If you're using namespace std; you don't need to use the scope resolution operator, you can just type ofstream fout; or whatever. I also don't understand why you've created two objects of ofstream (fout /* and */ file)

Your return 0; should be the last thing, right before the last brace (}) of your int main () function.

Very last line, there's a random semi-colon as well.

Okay, so start off with this:

1
2
3
4
5
6
7
8
// okay, if I'm not sure how to properly use file input output
// I'm going to try to get a line of code from the file first, before I do anything else with it

// after I have all of the values stored into different variables
// I'm going to display them to the screen to ensure it's working properly, then move on to the next step

// alright, got one line and it's displaying properly to the screen, now I'm going to do the same thing except I'm going to get several lines of input and display it
// so on and so forth as you slowly, SLOWLY build up your program's functionality 


Whenever I don't know how to do something, the last thing I want to do is confuse myself with a bunch of code. I start extremely simple in order to ensure I understand what's going on, and if something does go wrong (and trust me, it has, many times, it happens to everyone), it's drastically easier to fix when your program has a total of 10 lines of code in it (and thats including the includes, namespaces, and whatnot).
Last edited on
Topic archived. No new replies allowed.