Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Tax Calculator

Posted by Circuit Negma on March 20, 2006


      

/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *	Created By: Circuit Negma
 *
 *	Date	  : March 20, 2006
 *
 *	File	  : ch3_tax.cpp
 *
 *	Description: calculate taxes.
 */

// Declare Header Files
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
using namespace std;

	// Define Function dCheck() to check for double numbers.
	double dCheck()
	{
		bool flag;
		double i;
		 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
	    
	    return i;

	}


//***************************************************************
//***************************************************************
//***************** Build in Function main() ********************

int main()
{
	
	// Declare Fixed Variables
	static const int	fedinTax = 15;		// percentage
	static const double	stateTax = 3.5;		// percentage
	static const double	ssTax	 = 5.75;	// percentage
	static const double	mmTax	 = 2.75;	// percentage
	static const int	pp	 = 5;		// percentage
	static const int	hi	 = 75;		// Dollar
	
	// Declare Input Variables
	double grossAmount;
	string nameUser;
	char FirstName[100];
	char lastName[100];
	char FileName[100];
	
	// Declare Output Variables
	double FederalTax, SteTax;
	double SoSecTax, MedicareTax;
	double PensionPlan;
	double netPay;
	
	// Declare File Stream
	ofstream outData;
	
	// Get Data from user
	cout << fixed << showpoint << setprecision(2);
	cout << flush << endl;
	cout << "Please enter your FIRST name: " << flush;
	cin >> FirstName;
	cout << endl;
	cout << "Please enter your LAST name: " << flush;
	cin >> lastName;
	cout << endl;
	cout << "Please, Enter the Gross Income: " << flush;
	grossAmount = dCheck();
	
	// Creat output file
	strcpy(FileName, FirstName);
	strcat(FileName, lastName);
	strcat(FileName, ".txt");
	outData.open(FileName);

	// Print out some informations
	cout << flush << endl;
	outData << flush << endl;
	
	cout << setw(35) << left << setfill('.') << "Federal Income Tax: "
		 << " " << fedinTax << right << setw(3) << setfill(' ') << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Federal Income Tax: "
		 	<< " " << fedinTax << right << setw(3) << setfill(' ') << "%" << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "State Tax: "
		 << " " << stateTax << "%" << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "State Tax: "
		 	<< " " << stateTax << "%" << flush << endl;
	 
	cout << setw(35) << left << setfill('.') << "Social Security Tax: "
		 << " " << ssTax << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Social Security Tax: "
		 	<< " " << ssTax << "%" << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 << right << " " << setw(4) << mmTax << "%" << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 	<< right << " " << setw(4) << mmTax << "%" << flush << endl;
		 
	cout << setw(35) << left << setfill('.') << "Pension Plan: "
		 << " " << pp << right << setw(4) << setfill(' ') << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Pension Plan: "
		 	<< " " << pp << right << setw(4) << setfill(' ') << "%" << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Health Insurance: "
		 << " $" << hi << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << hi << flush << endl;	
	
	// Calculate the results
	FederalTax 	= fedinTax * grossAmount / 100;
	SteTax		= stateTax * grossAmount / 100;
	SoSecTax	= ssTax	   * grossAmount / 100;
	MedicareTax     = mmTax	   * grossAmount / 100;
	PensionPlan     = pp	   * grossAmount / 100;
	netPay		= grossAmount - FederalTax - SteTax - SoSecTax - MedicareTax
				  - PensionPlan - hi;
				  
	//Print out the results
	cout << flush << endl;
	outData << flush << endl;
	
	cout << FirstName << " " << lastName << flush << endl;
	outData << FirstName << " " << lastName << flush << endl;
	
	cout << setw(35) << left << setfill('.') << "Federal Tax: "
		 << " $" << right << setw(10) << setfill(' ') << FederalTax << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Federal Tax: "
		 	<< " $" << right << setw(10) << setfill(' ') << FederalTax << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "State Tax: "
		 << " $" << right << setfill(' ') << setw(10) << SteTax << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "State Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << SteTax << flush << endl;
	 
	cout << setw(35) << left << setfill('.') << "Social Security Tax: "
		 << " $" << right << setfill(' ') << setw(10) << SoSecTax << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Social Security Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << SoSecTax << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 << " $" << right << setfill(' ') << setw(10) << MedicareTax << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << MedicareTax << flush << endl;
		 
	cout << setw(35) << left << setfill('.') << "Pension Plan: "
		 << " $" << right << setw(10) << setfill(' ') << PensionPlan << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Pension Plan: "
		 	<< " $" << right << setw(10) << setfill(' ') << PensionPlan << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Health Insurance: "
		 << " $" << right << setw(10) << setfill(' ') << hi << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << right << setw(10) << setfill(' ') << hi << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Net Pay: "
		 << " $" << right << setw(10) << setfill(' ') << netPay << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << right << setw(10) << setfill(' ') << netPay << flush << endl;
	
	cout << endl << endl << endl;
	cout << "The above informations are saved to " << FileName << flush << endl;
	 
	outData.close();
	return 0;
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: