Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <iostream>
using namespace std;
int get_int(char msg[]);
double get_double(char msg[]);
double taxes(double rate,double tax[],double total,char status[],char filing[][2]);
void display(double rate,double total);
int main()
{
char buf[10];
char name[40];
char filing[5][2];
char status[3];
char msg[50];
char end = ' ';
double tax[4];
int no_dependents;
double wages;
double interest;
double dividends;
double other_income;
double total;
double rate = 0.0;
strcpy(filing[0],"S");
strcpy(filing[1],"MJ");
strcpy(filing[2],"MS");
strcpy(filing[3],"SH");
while(end != 'N')
{
printf("What is your name: ");
gets(name);
strcpy(msg,"\nWhat are your wages: ");
wages = get_double(msg);
strcpy(msg,"\nWhat is your interest: ");
interest = get_double(msg);
strcpy(msg,"\nWhat are your dividends: ");
dividends = get_double(msg);
strcpy(msg,"\nWhat are your other income amounts: ");
other_income = get_double(msg);
strcpy(msg,"How many dependents do you have: ");
no_dependents = get_int(msg);
printf("What is your martial status(S,MJ,MS,SH): ");
gets(status);
for(int i = 0;i < 2;i++)
status[i] = toupper(status[i]);
total = (wages + interest + dividends + other_income) - (no_dependents * 2800.00);
if(total <= 6000)
{
tax[0] = 2.8;
tax[1] = 0.0;
tax[2] = 2.3;
tax[3] = 0.0;
total = taxes(rate,tax,total,status,filing);
}
else if(total > 6000 && total <= 10000)
{
tax[0] = 7.5;
tax[1] = 5.2;
tax[2] = 7.2;
tax[3] = 3.8;
total = taxes(rate,tax,total,status,filing);
}
else if(total > 10000 && total <= 15000)
{
tax[0] = 9.6;
tax[1] = 8.3;
tax[2] = 8.9;
tax[3] = 7.4;
total = taxes(rate,tax,total,status,filing);
}
else if(total > 15000 && total <= 20000)
{
tax[0] = 13.5;
tax[1] = 12.2;
tax[2] = 13.1;
tax[3] = 11.0;
total = taxes(rate,tax,total,status,filing);
}
else if(total >20000 && total <= 25000)
{
tax[0] = 15.5;
tax[1] = 14.6;
tax[2] = 15.2;
tax[3] = 13.8;
total = taxes(rate,tax,total,status,filing);
}
else if(total > 25000 && total <= 30000)
{
tax[0] = 17.4;
tax[1] = 16.3;
tax[2] = 17.2;
tax[3] = 15.4;
total = taxes(rate,tax,total,status,filing);
}
else
total *= .35;
display(rate,total);
printf("Do you want to enter another user(Y or N): ");
gets(buf);
end = buf[0];
end = toupper(end);
}
return 0;
}
double taxes(double rate,double tax[],double total,char status[],char filing[][2])
{
for(int i = 0;i < 4;i++)
{
if(strcmp(status,filing[i]) == 0)
{
if(tax[i] != 0.0)
{
cout << "FILING VARIABLE: " << filing[i] << endl;
rate = tax[i] * .01;
cout << "RATE: " << rate << endl;
total = (total * rate) + total;
i = 5;
}
else;
}
}
return total;
}
void display(double rate,double total)
{
cout << rate << endl << total << endl;
printf("TAX: %d TOTAL: %d\n",rate,total);
}
int get_int(char msg[])
{
char buf[40];
printf(msg);
gets(buf);
return atoi(buf);
}
double get_double(char msg[])
{
char buf[40];
printf(msg);
gets(buf);
return atof(buf);
}