Sign in to follow this  

question

This topic is 3929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Write a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated after taking the following deductions. Federal Income Tax: 15% State Tax: 3.5% Social Security Tax: 5.75% Medicare/Medicaid Tax: 2.75% Pension Plan: 5% Health Insurance: $75.00 Your program should prompt the user to input the gross amount and the employee name. Format your output to have two decimal places> A sample output follows: The program should produce this type of output both on the display monitor and to a data file c:\lab5_data.txt. John Doe Gross Amount: ………… $3575.00 Federal Income Tax: ……. $ 536.25 State Tax: …………. ……. $ 125.13 Social Security Tax: ……… $ 205.56 Medicare/Medicaid Tax: .. $ 98.33 Pension Plan: ……………...$ 178.75 Health Insurance: …………. $ 75.00 Net Pay ……………………. $2356.00 Note that the first column is left-justified and the right column is right-justified. using ifstream my code is #include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std; int main() { ifstream indata; ofstream outdata; string firstname; string lastname; double income,state,federal,social,medicare,pension,health,netpay; indata.open("c:\\lab5_data.txt"); outdata.open("c:\\lab5.txt"); outdata<<fixed<<showpoint; outdata<<setprecision(2); indata>>firstname>>lastname; outdata<<"name:"<<firstname<<lastname<<endl; indata>>income; outdata<<"federal:"<<setw(6)<<federal<<endl; outdata<<"state:"<<setw(6)<<state<<endl; outdata<<"social:"<<setw(6)<<social<<endl; outdata<<"medicare/medicaid:"<<setw(6)<<medicare<<endl; outdata<<"pension:"<<setw(6)<<pension<<endl; outdata<<"health:"<<setw(6)<<health<<endl; outdata<<"netpay:"<<setw(6)<<netpay<<endl; indata.close(); outdata.close(); return 0; } when i execute nothing happens except the screen saying press any key to continue

Share this post


Link to post
Share on other sites
You're writing your output to a file and reading from a file. There's nothing there that says "display output on screen". Have a look at lab5.txt, maybe there's a surprise inside. =)

You probably want to use cin/cout. Also, you probably don't want to post homework assignments here.

Share this post


Link to post
Share on other sites
well i was trying to get the file to open in the code.
and why not post assignments not like im telling you to do it for me just asking for help whats so wrong with that

Share this post


Link to post
Share on other sites
-Is the output file being generated?
-Are you executing from within the compilier IDE?, or double-clicking?

I noticed that your main() will immediately return execution, nor
print out anything, which is why it looks like it doesnt do anything.

Some win32 compiliers embed "Press any key.." at the end of counsole programs
when running in the compilier IDE. This wont happen when ran outside the IDE.

Double click the *.exe, and tell us what happens..

Quote:

and why not post assignments not like im telling you to do it for me just asking for help whats so wrong with that

Most people frown when one is posting about homework because most people
posting about homework expects someone to do it for them.

Coinsidering you are asking for help on specific code (Im assuming you wrote),
it should be okay.

Share this post


Link to post
Share on other sites
yea im just looking for help not someone to write it i already wrote the code and dont really get why nothing happens i was expecting the file lab5_data.txt to open

Share this post


Link to post
Share on other sites
-Insure lab5_data.txt is in your C: directory. It wont be created for you.

-Test if the fstream::open() methods are failing:

indata.open("c:\\lab5_data.txt");
if (indata.fail())
cout << "No input file found" << endl;

outdata.open("c:\\lab5.txt");
if (outdata.fail())
cout << "Unable to find or create output file" << endl;



I have tried your code on my machine (Modified with the above), and it works
fine.

Share this post


Link to post
Share on other sites

This topic is 3929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this