ok im not sure if this is an array problem but anyway here it is.
my problem is im passing some values into a function called taxes and its supposed to return the total which it does however inside of that function im comparing to see whether the person is(S,MJ,MS,SH which are stored in a variable called filing) based on there answer which is stored in status.
the problem from what i can see is it seems to work sometimes but not other times. in that function like the comparison and for look turn out right sometimes but not other times and im not exactly sure why. i think this is the problem but i could be wrong? cause the test data i wrote out on paper before i made this program worked and then when i typed out the program that specific test data works but then not everything else seems to work and i know this cause it doesnt run through that loop correctly. it should only not do calculations in that taxes function if a 0.0 is passed in for the tax and when it doesnt calculate something when it should it has to be screwing up somewhere around there is my guess?
also note im aware this board hates the gets() function but its for school so leave it and also i know i have some cout's placed but its just cause its alot easier to deal with for test statements to see if i have my output correct or not rather than dealing with printf()'s percent signs that imstill not 100% familar with.
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);
}