C++ help with code in inFile stream

blueeyes53's Avatar, Join Date: Feb 2007
Newbie Member
Hi there I am in the learning process, and I am getting a lot of errors while trying to write this code for:

I have already the input file, and the outFile, but I can't get the updated info that I need.

ex: There is a file with this information:

Miller Andrew 65789.87 5%
Green Sheila 75892.56 6%
Sethi Amit 74900.50 6.1%

For each employee the output should be in the following form:

firstName lastName updatedSalary.
Format output of decimal numbers to two decimal places

Three employees in a company are up for a special pay increase. You

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

using namespace std;

int main()


	ifstream inFile;
	ofstream outFile;

	double data1, data2, data3;

    double updated_Salary;

	string firstName;
	string lastName;


	outFile << fixed << showpoint;
	outFile << setprecision(2);

	cout << " Processing data " << endl;

	inFile >> firstName >> lastName >> current_salary >> pay_increase;

	outFile << " Employee's name: " << firstName << " last name "
		<< lastName << " current salary " << current_salary
		<< " pay increase " << pay_increase  << endl;

	inFile >> miller >> green >> sethi;

	outFile << " Pay increase " << setw(6) << miller << setw(6) 
		<< green << setw(6) << sethi << endl;


return 0;


Any help will be very appreciated
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You don't say what your problem is. Are we to guess? You also don't say how three employees listed in the file are to be determined as the special ones among the many. Are we to guess? Let me assure you that information is key to getting answers, just as it is in debugging. Please consider that when you seek help.
blueeyes53's Avatar, Join Date: Feb 2007
Newbie Member
Miller Andrew currentSalary 65789.87 5%increase of currentSalary, and get the output as updatedSalary

Green Sheila currentSalary 75892.56 6%increase of currentSalary, and get the output as updatedSalary

Sethi Amit currentSalary 74900.50 6.1%increase of currentSalary, and get the output as updatedSalary
output should be to calculate the currentSalary example:
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You still don't say what your problems are. The code looks very garfled up. You appear to be getting information from infile and putting it in variables miller, green, and sethi, but I don't see those variables declared anywhere. There's an implication that those variables are to hold the pay increase, but you're doing nothing to calculate that increase. You also don't say if the increase should be the percentage, although there is an implication that it should be the updated salary.

Furthermore, you're doing one input of first and last names, salary, and increase. That would get information for the first person. Further reads would get input for the second person, not three increase values in a row.

Are those the only entries in the file? You need to say more. What compiler errors are you getting. I find it difficult to believe that the program compiled and ran. If it does, explain how it is that the program is not meeting your expectations.

Your post is absolutely terrible in terms of getting any kind of decent response. You must learn how to convey information. Sometime I use a crystal, but it's in the shop for "ball" joints. You're going to have to shoulder the responsibility. Here is some information that I've promulgated in the past. It doesn't all apply to you, and it repeats some of the material in this forum's "Before you make a query" thread. Read it all, anyway, and think about how to ask your question in such a way as to give us as much help as possible. The return on that investment will be much better, I promise you.

Here are some general guidelines.


There is a chance that your problem has already been addressed on this forum before (or even multiple times before for some issues).

Use the forum's search feature first to see if there are already some good threads on the subject.


I cannot stress this enough. We cannot possibly help you if you simply post a thread, copy and paste your whole code and say "it has errors what's wrong with it?". Keep this in mind:

1. Explain to us what your code DOES (or what it's supposed to do).

2. Explain to us what exactly the error is. What kind of error? Or is it just not doing what you want?

3. Remember that you know a lot more about your code than we do. Don't assume we know just what it does.

Don't use stupid topic names

Post a descriptive topic name! Give a short summary of your problem IN THE SUBJECT. Don't use attention getting subjects. They don't get attention. They repel attention and annoy people.

Here's a great list of topic subjects YOU SHOULD NOT POST:

1) Help me
2) Hello
3) You must know the answer
4) Please help this newbie
5) Something wrong
6) Come on gurus
7) This one for you
8) Just wondering
9) This is too complicated for me
10) Possible?
11) Very urgent
12) I have a question
13) Stupid question
14) Newbie needs help
15) Pulling my hair out
16) This is driving me nuts
17) See if you can solve this real challenge
18) Sexy blonde needs help

Generally ANYTHING similar to those is unacceptable. Just post your problem.

Here is a good example of a way to post a question about an input file function named get():

"File input error w/ get()"

These are bad examples:

"I can't figure this out!"
"Stupid question..."
"Newbie needs regex help"
"Help me! Urgent!"


PLEASE do not post your entire code in a message. And if you have to use 2 messages that's a good indication that you're going to annoy people. Only post the part of your code where you have problems. That's it. Just a very small piece of it. It's not hard. Just find the part you think doesn't work and post that. WE DON'T WANT TO SEE YOUR ENTIRE CODE. If you post the entire code it's going to take us a lot longer to find the problem.

PUT YOUR CODE IN in code tags!

Don't post code right into the message. There's a problem with that: the tabs or extra spaces don't work!

There's a solution to this, namely 'code tags', press the code button (with the # image) and post your code inbetween. Which will look like:


// this is some easy to read code if(expression) { great(); }

If you get an error on a certain LINE, tell us what's on that line and what's on the few lines above it!

It's not too helpful when you mention an error on a certain line but don't tell us what code is on that line. Because errors can sometimes be caused by lines of code above the one the error is mentioned on, please post a few lines above that line.

Only you know what "doesn't work" means.

Please tell us what your code is supposed to do and why it "doesn't work". Or if you don't feel like explaining what the whole code is, at least tell us what the offending code is supposed to do. When you come in and say "it doesn't work" or just "it has errors", that means NOTHING. There could be a million things wrong and no one will know where to look.

If you're not going to take the advice, don't ask for help.

Often times, people post questions about their code with the wrong mindset from the very beginning. Soon they are receiving replies, and silently debugging their code, making no effort to even acknowledge the people helping them! It becomes one sided, and the poster isn't aware that many of the people helping them hope to learn something as well! Letting people know of your progress and how their suggestions apply (or do not apply) will not only help you figure out your problem quicker, but you'll be returning the favor to those of us who learn more by helping.

In even worse scenarios, sometimes the poster will argue back even when they don't know what they're talking about. Hey - if you know it all, don't ask for help.

When people give you free code that may solve your problem, by all means, try it out! And if it's not what you need, at least thank them.

And if people post code that is over your head, ask them for an explanation. Too many times I see great solutions posted, then the original poster doesn't understand it and goes hunting through the manual and finds some function they think will solve their problem but really has Nothing to do with their problem! The solution you are given may not always be something you are totally familiar with, so just ask for a better explanation!

Remember when people help you, they are doing YOU a favor

Regardless of how big your ego is, it is NOT someone else's privilege to debug Your code. It is not their privilege to have them help you. It is YOURS. Remember that when people help you they are doing YOU a favor. You are not doing them a favor by letting them see your incredible application. Be patient, help people out by posting good descriptions of what you need help with, and not snapping at people with garbage such as "if you aren't going to help don't waste my time replying".