View Single Post
bandora's Avatar
Posts: 1,338 | Thanked: 1,055 times | Joined on Oct 2009 @ California, USA / Jordan
#1
Hey all,

I know this might sound silly... But I need help in a simple thing...

So the output of the code should look like this..

Code:
Dongxiao
Gross Amount: ............ $1000.00
Federal Tax: ............. $ 150.00
State Tax: ............... $  35.00
Social Security Tax: ..... $  57.50
Medicare/Medicaid Tax: ... $  27.50
Pension Plan: ............ $  50.00
Health Insurance: ........ $  75.00
Net Pay: ................. $ 605.00
Now I got the code to work to give me the above numbers.. But I don't know how to align it properly exactly like how it's shown above and I don't know how to add the "..." automatically as needed..

Here's my code so far:

Code:
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//Experimenting with this, but didn't work out

//const char* text = "Constant text ";
//const size_t MAXWIDTH = 14;
//
//void print(const string& var_text, int num)
//{
//    cout << text
//              // align output to left, fill goes to right
//              << left << setw(MAXWIDTH) << setfill('.')
//              << var_text << ": " << num << '\n';
//}

int main()
{
	string name;
	int x;
	double FedIncTax, //Federal Income Tax
		StateTax, //State Tax
		SSTax, //Social Security Tax
		MedTax, // Medicare/Medicaid Tax
		PenPlan, //Pension Plan
		HealthIns = 75, //Health Insurance
		GrossAmnt, //Gross amount
		NetPay; //Net Pay
	
	//Input
	cout<<"Enter your name: ";
	cin>>name;
	cout<<"Enter your Gross amount: ";
	cin>>GrossAmnt;

	//Calculations
	FedIncTax = (GrossAmnt * 0.15);
	StateTax = (GrossAmnt * 0.035);
	SSTax = (GrossAmnt * 0.0575);
	MedTax = (GrossAmnt * 0.0275);
	PenPlan = (GrossAmnt * 0.05);
	NetPay = GrossAmnt - (FedIncTax + StateTax + SSTax + MedTax + PenPlan + HealthIns);
	
	//Output
	cout<< name <<endl;
	cout<<fixed<<setprecision(2);
	cout<<"Gross Amount: "<<setfill('.')<<setw(14)<<" $"<<GrossAmnt<<endl;
	cout<<"Federal Tax: "<<setfill('.')<<setw(15)<<" $"<<FedIncTax<<endl;
	cout<<"State Tax: "<<setfill('.')<<setw(17)<<" $"<<right<<StateTax<<endl;
	cout<<"Social Security Tax: "<<setfill('.')<<setw(7)<<" $"<<right<<SSTax<<endl;
	cout<<"Medicare/Medicaid Tax: "<<setfill('.')<<setw(5)<<" $"<<right<<MedTax<<endl;
	cout<<"Pension Plan: "<<setfill('.')<<setw(14)<<" $"<<right<<PenPlan<<endl;
	cout<<"Health Insurance: "<<setfill('.')<<setw(10)<<" $"<<right<<HealthIns<<endl;
	cout<<"Net Pay: "<<setfill('.')<<setw(19)<<" $"<<right<<NetPay<<endl;

	return 0;
}
Any help would be greatly appreciated!

Thanks in advance.

EDIT: And just so you can be filled in on what I'm talking about.. This is what the homework says..

(25 points) 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. The output will be stored in a file. Format your output to have two decimal places. Your output should be formatted to two columns. The first column is left-justified, and the right column is right-justified.
EDIT: I updated the code and fixed the issue with the "...", but I have an issue with the alignment (especially with the result numbers)..
__________________
FarahFa.com

Last edited by bandora; 2013-09-20 at 04:48. Reason: Updated the code and fixed some of the issues..
 

The Following User Says Thank You to bandora For This Useful Post: