Staredit Network > Forums > Technology & Computers > Topic: Another C++ Question
Another C++ Question
Sep 26 2007, 10:45 pm
By: l3lack-l3ahamut  

Sep 26 2007, 10:45 pm l3lack-l3ahamut Post #1



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.

Sep 26 2007, 11:25 pm Matt Burch Post #2



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:
Code
/*
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:
Code
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.

Sep 26 2007, 11:33 pm l3lack-l3ahamut Post #3



maybe I'll just copy the source into a few project and see if it works then.



None.

Sep 26 2007, 11:36 pm AntiEsponeo Post #4



Works fine for me too.



None.

Sep 26 2007, 11:39 pm l3lack-l3ahamut Post #5



seriously? it gave the same errors again...



None.

Sep 26 2007, 11:41 pm Matt Burch Post #6



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.

Sep 26 2007, 11:43 pm l3lack-l3ahamut Post #7



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.

Sep 26 2007, 11:54 pm Matt Burch Post #8



Try doing:
Code
cout << "Enter employee's first and last name: " << flush;
getline(cin, fname, ' ');
getline(cin, lname);

You'll need to change that other line to:
Code
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.

Sep 27 2007, 12:00 am l3lack-l3ahamut Post #9



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.

Sep 27 2007, 1:45 am ShadowFlare Post #10



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.

Sep 27 2007, 2:20 am Falkoner Post #11



Man! You guys make your programs really hard to read! Space things out!



None.

Sep 27 2007, 3:39 am Twitch Post #12



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.

Sep 27 2007, 2:00 pm l3lack-l3ahamut Post #13



Quote from ShadowFlare
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.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[2024-4-22. : 6:48 pm]
Ultraviolet -- :wob:
[2024-4-21. : 1:32 pm]
Oh_Man -- I will
[2024-4-20. : 11:29 pm]
Zoan -- Oh_Man
Oh_Man shouted: yeah i'm tryin to go through all the greatest hits and get the runs up on youtube so my senile ass can appreciate them more readily
You should do my Delirus map too; it's a little cocky to say but I still think it's actually just a good game lol
[2024-4-20. : 8:20 pm]
Ultraviolet -- Goons were functioning like stalkers, I think a valk was made into a banshee, all sorts of cool shit
[2024-4-20. : 8:20 pm]
Ultraviolet -- Oh wait, no I saw something else. It was more melee style, and guys were doing warpgate shit and morphing lings into banelings (Infested terran graphics)
[2024-4-20. : 8:18 pm]
Ultraviolet -- Oh_Man
Oh_Man shouted: lol SC2 in SC1: https://youtu.be/pChWu_eRQZI
oh ya I saw that when Armo posted it on Discord, pretty crazy
[2024-4-20. : 8:09 pm]
Vrael -- thats less than half of what I thought I'd need, better figure out how to open SCMDraft on windows 11
[2024-4-20. : 8:09 pm]
Vrael -- woo baby talk about a time crunch
[2024-4-20. : 8:08 pm]
Vrael -- Oh_Man
Oh_Man shouted: yeah i'm tryin to go through all the greatest hits and get the runs up on youtube so my senile ass can appreciate them more readily
so that gives me approximately 27 more years to finish tenebrous before you get to it?
[2024-4-20. : 7:56 pm]
Oh_Man -- lol SC2 in SC1: https://youtu.be/pChWu_eRQZI
Please log in to shout.


Members Online: Roy, IlyaSnopchenko