C++ A little homework help, Thanks very much for the last assistance

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 37
Reputation: radskate360 is an unknown quantity at this point 
Solved Threads: 0
radskate360 radskate360 is offline Offline
Light Poster

C++ A little homework help, Thanks very much for the last assistance

 
-1
  #1
May 24th, 2007
IF anyone can give me a little more assistance I would be very greatful.

I am working on this program for my C++ class and here is how it goes.

Directions.

Write a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated after taking the following deductions.
Federal Tax 15%
State Tax 3.5%
Social Securtiy Tax 5.75%
Medicare 2.75%
Pension 5%
Health Ins $75.00
Your program shoud prompt user for input of employee name, and gross amount. The output will be stored into a file. format your output to have two decimal perscion.


As for when I run the program I type in the Employee name when prompted for name and then it prompts for Gross amount but doesnt wait for an answer.

Here is what I have so far:

string employee;
double gross;
double federal, state, ss, med, pension, health, net;

cout << "What is the Employees Name " << endl;
cin >> employee;
cout << "What is the Employees Gross Pay " << endl;
cin >> gross;

fstream fout;
fout.open ("taxes");
federal = (gross * .15);
fout << "Federal Tax" << federal << endl;
state = (gross * .035);
fout << "State Tax" << state << endl;
ss = (gross * .0575);
fout << "Social Security Tax" << ss << endl;
med = (gross * .0275);
fout << "Medicare/Medicaid Tax" << med << endl;
pension = (gross * .05);
fout << "Pension Plan" << pension << endl;
health = 75.00;
fout << " Health Insurance" << health << endl;
net = (gross - (federal + state + ss + med + pension + health));
fout << "Net Pay" << net << endl;

Not sure if I am on the write track but any help would be greatly appreciated.

Thanks ,
Alot
A
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: C++ A little homework help, Thanks very much for the last assistance

 
0
  #2
May 24th, 2007
you are probably trying to enter a name that has embedded (white) spaces. to read an entire line (may contain white spaces) use getline.
getline( cin, employee ) ;
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 62
Reputation: minigweek is on a distinguished road 
Solved Threads: 4
minigweek's Avatar
minigweek minigweek is offline Offline
Junior Poster in Training

Re: C++ A little homework help, Thanks very much for the last assistance

 
0
  #3
May 24th, 2007
Yes, that is indeed the case. For cin , white space is a terminator, and the rest of the name stays in the input stream. the next cin statement reads from the remaining input buffer.
cin.get , will help u read the name inclusive of white spaces.
for
char name[20];
use
cin.get(name,19);

now it should work lets us know here.
I was born Genius, but some loser Leeched it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: C++ A little homework help, Thanks very much for the last assistance

 
0
  #4
May 24th, 2007
>for
>char name[20];
>use
>cin.get(name,19);
He's already using std::string. Why are you suggesting that he downgrade to C-style strings? Oh, and you have an off-by-one logic bug. The size argument to get should be 20. Finally, you should recommend getline instead of get, because get has the potentially confusing feature of leaving the delimiter in the stream. In this case, unless you hit one of the less common terminating cases, you get the infamous scanf "bug":
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. char buff[20];
  6.  
  7. std::cin.get ( buff, 20 );
  8. std::cout<<'|'<< buff <<"|\n";
  9. std::cin.get ( buff, 20 );
  10. std::cout<<'|'<< buff <<"|\n";
  11. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC