i have written my homework problem but get 7 errors in it. the errors seem to be comming from this line as well as others like it. any help would be greatly appreciated. this is my first year doing this and is somewhat confusing.

I need these lines to be on the screen when prompted.
indata >> left >> setw(22) >> "Federal Tax" >> right >> setw(14) >> federal >> endl;
state = (gross * .035);
indata >> left >> setw(22) >> "State Tax" >> right >> setw(14) >> state >> endl;
ss = (gross * .0575);
indata >> left >> setw(22) >> "Social Security Tax" >> setw(14) >> ss >> endl;
med = (gross * .0275);
indata >> left >> setw(22) >> "Medicair/Medicaid Tax" >> setw(14) >> med >> endl;
pension = (gross * .05);
indata >> left >> setw(22) >> "Pension Plan" >> setw(14) >> pension >> endl;
health = 75.00;
indata >> left >> setw(22) >> "Health Insurance" >> setw(14) >> health >> endl;
net = (gross-(federal + state + ss + med + pension + health));
indata >> left >> setw(22) >> "Net Pay" >> setw(14) >> net >> endl;
the error message says this:

c:\program files\microsoft visual studio 8\vc\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
how do i go about fixing this. thanks

how is indata declared ? Is it a member of istream?

this is nwhat it looks like. i am not sure what you mean. thanks

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

using namespace std;
string employeeFirst, employeeLast;
double gross;
double federal, state, ss, med, pension, health, net;


int main()
{

cout << "what is the Employees Name" << endl;
cin >> employeeFirst >> employeeLast;
cout << "What is the Employees Gross Pay" << endl;
cin >> gross;

cout << fixed << showpoint << setprecision (2);
cout << setfill ('.');

ifstream infile;
ofstream outfile;
indata.open ("PayrollTaxes");
federal = (gross * .15);
indata >> left >> setw(22) >> "Federal Tax" >> right >> setw(14) >> federal >> endl;
state = (gross * .035);
indata >> left >> setw(22) >> "State Tax" >> right >> setw(14) >> state >> endl;
ss = (gross * .0575);
indata >> left >> setw(22) >> "Social Security Tax" >> setw(14) >> ss >> endl;
med = (gross * .0275);
indata >> left >> setw(22) >> "Medicair/Medicaid Tax" >> setw(14) >> med >> endl;
pension = (gross * .05);
indata >> left >> setw(22) >> "Pension Plan" >> setw(14) >> pension >> endl;
health = 75.00;
indata >> left >> setw(22) >> "Health Insurance" >> setw(14) >> health >> endl;
net = (gross-(federal + state + ss + med + pension + health));
indata >> left >> setw(22) >> "Net Pay" >> setw(14) >> net >> endl;






	return 0;
}

how is indata declared ? Is it a member of istream?

i was trying to fix it but now i have 2 messages. they are:

error C2065: 'indata' : undeclared identifier
c:\documents and settings\mike\my documents\visual studio 2005\projects\homework assignment 1\homework\homework.cpp(26) : error C2228: left of '.open' must have class/struct/union
i do not understand what they mean by 'indata' : undeclared identifier
and left of '.open must have class/struct/union
any help with this would be greatly appreciated

>ifstream infile;
You define infile, but then proceed to use indata. Perhaps you meant to define indata rather than infile?

>ifstream infile;
You define infile, but then proceed to use indata. Perhaps you meant to define indata rather than infile?

i put in ifstream indata and then it gave me 7 errors this is what i had written: what do you think i did wrong to get 7 errors? i know the lines with indata are the ones that are wrong but how do i fix them? I am clueless. i have been on this all afternoon.

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


using namespace std;
string employeeFirst, employeeLast;
double gross;
double federal, state, ss, med, pension, health, net;


int main()
{

cout << "what is the Employees Name" << endl;
cin >> employeeFirst >> employeeLast;
cout << "What is the Employees Gross Pay" << endl;
cin >> gross;

cout << fixed << showpoint << setprecision (2);
cout << setfill ('.');

ifstream indata;
indata.open ("PayrollTaxes");
federal = (gross * .15);
indata >> left >> setw(22) >> "Federal Tax" >> right >> setw(14) >> federal >> endl;
state = (gross * .035);
indata >> left >> setw(22) >> "State Tax" >> right >> setw(14) >> state >> endl;
ss = (gross * .0575);
indata >> left >> setw(22) >> "Social Security Tax" >> setw(14) >> ss >> endl;
med = (gross * .0275);
indata >> left >> setw(22) >> "Medicair/Medicaid Tax" >> setw(14) >> med >> endl;
pension = (gross * .05);
indata >> left >> setw(22) >> "Pension Plan" >> setw(14) >> pension >> endl;
health = 75.00;
indata >> left >> setw(22) >> "Health Insurance" >> setw(14) >> health >> endl;
net = (gross-(federal + state + ss + med + pension + health));
indata >> left >> setw(22) >> "Net Pay" >> setw(14) >> net >> endl;






	return 0;
}

Let me take a wild guess. cin doesn't like that you're trying to use string literals when there isn't an overloaded operator>> that takes a string literal. :)

Let me take a wild guess. cin doesn't like that you're trying to use string literals when there isn't an overloaded operator>> that takes a string literal. :)

What do you mean by that? I am still just learning about this stuff. could you show me an example
thanks i really appreciate all this help

Look at line 27 for example. indata is an INPUT stream and you are attemtping to INPUT a char* literal. Can't be done. input streams require variables to accept the data. If your intent is to write the strings and other data to a file then you need an OUTPUT stream, ofstream and use the output operator <<.

Look at line 27 for example. indata is an INPUT stream and you are attemtping to INPUT a char* literal. Can't be done. input streams require variables to accept the data. If your intent is to write the strings and other data to a file then you need an OUTPUT stream, ofstream and use the output operator <<.

WHAT IF I JUST WANT IT TO DISPLAY ON THE COMPUTER SCREEN AND NOT TO A FILE. WHAT WOULD I HAVE TO CHANGE IN ORDER TO DO THAT. THIS IS VERY CONFUSING. THIS IS MY FIRST CLASS IN C++ PROGRAMMING AND I AM REALLY TRYING TO UNDERSTAND THIS. I REALLY APPRECIATE ALL THE HELP EVERYONE IS GIVING ME. I AM CERTAINLY GOING TO TELL MY CLASSMATES ABOUT THIS WEBSITE.

>>WHAT IF I JUST WANT IT TO DISPLAY ON THE COMPUTER SCREEN AND NOT TO A FILE
Please don't use all caps like that -- its like screaming at us. If you want to display something on the screen then use cout

cout << "Hello World\n";

The above will show the text on the screen. Notice that OUTPUT always use the << operator, and INPUT uses the >> operator. The two can not be confused or used interchangeably.

line 17 should be coded like below. Note that it does not use indata variable at all, but uses the standard c++ cout which is declared for you in iostream header file.

cout << left << setw(22) << "Federal Tax" << right << setw(14) << federal << endl;

>>WHAT IF I JUST WANT IT TO DISPLAY ON THE COMPUTER SCREEN AND NOT TO A FILE
Please don't use all caps like that -- its like screaming at us. If you want to display something on the screen then use cout

cout << "Hello World\n";

The above will show the text on the screen. Notice that OUTPUT always use the << operator, and INPUT uses the >> operator. The two can not be confused or used interchangeably.

line 17 should be coded like below. Note that it does not use indata variable at all, but uses the standard c++ cout which is declared for you in iostream header file.

cout << left << setw(22) << "Federal Tax" << right << setw(14) << federal << endl;

sorry about that i didn't realize i did that. would i change all the lines with the cout on lines 27,29,31,33,35,37,39 and what about line 24 and 25 do they need to be changed?

>>and what about line 24 and 25 do they need to be changed?
No, leave them alone because you have not finished that code yet. After fixing all those lines you mentioned I suspect you need to add more code to read the variables from a data file so that they can be displayed on the screen. But you haven't said anything about that data file.

i ended up getting it to work but the payroll taxes (line 25) should not be on the screen. i don't know how to right justify the other taxes. can you help me with this? the outcome should look like this

joe shmo
gross amount...........................
federal tax...............................
state tax..................................
social security tax.....................
medicare/medicaid tax..............
pension plan.............................
health insurance.......................
net pay....................................

>>can you help me with this
Sorry, sadly I'm not really all that good at that either in c++, I know the basics. Hopefully someone else will read this and give you a hand. In the meantime I suggest you just test out different things to see if you can get it to work yourself.

>>can you help me with this
Sorry, sadly I'm not really all that good at that either in c++, I know the basics. Hopefully someone else will read this and give you a hand. In the meantime I suggest you just test out different things to see if you can get it to work yourself.

do you know how to get gross amount on its own line with the figure at the end. i get the error message of 'set': identifier not found. how can i set the gross amount based on the program from earlier. what do i need to type in? nay ideas?
thanks

This article has been dead for over six months. Start a new discussion instead.