When attempting to compile my program it has 2 errors which both state: "C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)"
Here is my program;
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
int main()
{
double gross,
federal,
state,
sSecurity,
medicare,
pension,
hInsurance = 75.0,
net;
string fname,
lname;
cout << "Enter employee's first and last name: " << flush;
cin >> fname >> lname;
First error on this line cout << "\nEnter employee's gross pay: " << flush;
cin >> gross;
federal = 0.15 * gross;
state = 0.035 * gross;
sSecurity = 0.0575 * gross;
medicare = 0.0275 * gross;
pension = 0.05 * gross;
net = gross - federal - state - sSecurity - medicare - pension - hInsurance;
cout << "\n\n" << fname << lname
Second error on this line << "\nGross pay: " << gross
<< "\nFederal tax: " << federal
<< "\nState tax: " << state
<< "\nSocial Security tax: " << sSecurity
<< "\nMedicare / Medicade tax: " << medicare
<< "\nPension plan: " << pension
<< "\nNet pay: " << net << endl;
return 0;
}
I'd appreciate any help with this.
None.
On xCode (Mac) it shows no errors. I don't know what you are doing wrong. This looks like the Computer Science 20S assignment I had last year. Mine is canadian though.
The one I wrote was:
/*
Name: Oops... hehehe.
Date: May 8th 2007
Assignment: 3-1
This program asks for the number of hours worked in a week, and your hourly wage. To calculate your total wages, and your tax deductions, outputing your net income.
*/
#include <iomanip.h>
int main()
{
cout.setf(ios::fixed, ios::floatfield);
cout<<setprecision(2);
float regular_Time, rate_Of_Pay, total_Wages, overtime, income_Tax, provincial_Tax, cpp, ei, net_Income, regular_Wage, overtime_Wage;
cout<<"\n\n\tThis program will calculate your total wages, tax deductions, and your net income. Input your hours works and your wage.\n\n\thours worked: ";
cin>>regular_Time;
cout<<"\tHourly wage: ";
cin>>rate_Of_Pay;
total_Wages = (regular_Time * rate_Of_Pay );
overtime = regular_Time - 40;
regular_Wage = rate_Of_Pay * ( regular_Time - overtime );
overtime_Wage = ( ( rate_Of_Pay * 1.5 ) * overtime );
if ( regular_Time > 40 )
{
total_Wages = regular_Wage + overtime_Wage;
} else if ( regular_Time <= 40 )
{
total_Wages = regular_Wage;
}//end if
income_Tax = ( total_Wages * 0.17 );
provincial_Tax = ( total_Wages * 0.07 );
cpp = ( total_Wages * 0.039 );
ei = ( total_Wages * 0.0255 );
net_Income = ( total_Wages - income_Tax - provincial_Tax - cpp - ei );
cout<<setprecision(0)<<"\n\n"<<regular_Time<<setprecision(2)<<" hours at $"<<rate_Of_Pay<<"/hour\n\t";
cout<<setprecision(0)<<regular_Time - overtime<<setprecision(2)<<" hours regular time"<<setw(17)<<regular_Wage<<"\n\t";
cout<<setprecision(0)<<overtime<<" hours overtime"<<setprecision(2)<<setw(22)<<overtime_Wage<<"\n\t";
cout<<"Total wages"<<setw(27)<<total_Wages<<"\n\n\t";
cout<<"Income Tax"<<setw(28)<<income_Tax<<"\n\t";
cout<<"Provincial Tax"<<setw(24)<<provincial_Tax<<"\n\t";
cout<<"CPP"<<setw(35)<<cpp<<"\n\t";
cout<<"EI"<<setw(36)<<ei<<"\n\n\t";
cout<<"Net Income"<<setw(28)<<net_Income;
return 0;
}//end int main
When I run the program, I got:
Enter employee's first and last name: John Doe
Enter employee's gross pay: 450.00
JohnDoe
Gross pay: 450
Federal tax: 67.5
State tax: 15.75
Social Security tax: 25.875
Medicare / Medicade tax: 12.375
Pension plan: 22.5
Net pay: 231
Vhaeraun has exited with status 0.
Post has been edited 2 time(s), last time on Sep 26 2007, 11:26 pm by Matt Burch. Reason: Stupid "4"!! Grr..
None.
maybe I'll just copy the source into a few project and see if it works then.
None.
seriously? it gave the same errors again...
None.
Are you using a mac? On xCode? Because lots of programs I make on xCode on my Mac, don't work on windows at all.
None.
No I'm using Visual C++ Express on windows. This is the first time its been like this.
[edit]
well it worked after I changed the string.h to just <string> which didn't work the first time either so idk but it works now.
Post has been edited 1 time(s), last time on Sep 26 2007, 11:54 pm by Vhaeraun.
None.
Try doing:
cout << "Enter employee's first and last name: " << flush;
getline(cin, fname, ' ');
getline(cin, lname);
You'll need to change that other line to:
cout << "\n\n" << fname << " " << lname
to have it have the name seperated when it displays it.
I'll think a bit more, for the second part.
None.
well I got it to work then I started adding more to it and now it wont even link:
"1>LINK : fatal error LNK1168: cannot open C:\Documents and Settings\Mike\My Documents\Visual Studio 2005\Projects\prog ex 6\Debug\prog ex 6.exe for writing"
None.
That means that your program is probably still running. Check the task manager process list for your program, if needed. If it isn't there, then just try building it again. Occasionally it gives that error on your first try building projects even if your program isn't running.
None.
Man! You guys make your programs really hard to read! Space things out!
None.
I tried this aswell it gave me the same errors I use dev C++ so I don't know how a mac user gets it to work.Try renaming those lines and see if it fixes it I have done that before and it fixed :l.
None.
That means that your program is probably still running. Check the task manager process list for your program, if needed. If it isn't there, then just try building it again. Occasionally it gives that error on your first try building projects even if your program isn't running.
Yeah I tried that but it wasn't even running and I've tried to build it like 20 times.
None.