I have my program working. I just need to redo it a little bit, and it could use some improvements.
I got different % rates depending on what the income and status is.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <cstdio>
//functions called
float wages_loop();
float other_loop();
float interest_loop();
float dividends_loop();
int dependatnts_loop();
void check_status();
float get_total_income(float wage, float div, float intre, float other, int dep);
int single_total = 0;
int mj_total = 0;
int ms_total = 0;
int sh_total = 0;
//start main
int main(void)
{
char another[10];
char buffer[80][90];
float wages, other_income, interest, dividends, income_tax;
int dependents;
printf("Would you like to start: ");
gets_s(another);
if (another[0] != 'y' && another[0] != 'n')
{
while (another[0] != 'y' && another[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Would you like to start. (y or n)");
gets_s(another);
}
}
while (another[0] == 'y')
{
//add all info together.
wages = wages_loop();
other_income = other_loop();
interest = interest_loop();
dividends = dividends_loop();
//enter dependats
dependents = dependatnts_loop();
//function to indicate the status and other things.
income_tax = get_total_income(wages, other_income, dividends, interest, dependents);
if (income_tax < 0)
{
printf("\n\n\t\t Your income tax RETURN is: %.2f \n", income_tax);
}
else if (income_tax >= 0)
{
printf("\n\n\t\t Your income tax OWED is: %.2f \n", income_tax);
}
printf("Would you like to do anoter: ");
gets_s(another);
if (another[0] != 'y' && another[0] != 'n')
{
while (another[0] != 'y' && another[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Would you like anoter. (y or n)");
gets_s(another);
}//end if
}
} //end loop
printf("\n\n\t\t\t Number of Singles filleing: %i \n", single_total);
printf("\n\n\t\t\t Number of Married Filing Jointly: %i \n", mj_total);
printf("\n\n\t\t\t Number of Married Filing Separately: %i \n", ms_total);
printf("\n\n\t\t\t Number of Single Head of Household filleing: %i \n", sh_total);
system("pause");
return 0;
}//end main
float wages_loop()
{
char again[10];
char buffer[80];
float wages, total_wages = 0;
printf("\n How much in Wages. ");
gets_s(buffer);
wages = atof(buffer);
total_wages = wages + total_wages;
printf("\n Do you have any more wages. (y or n)");
gets_s(again);
if (again[0] != 'y' && again[0] != 'n')
{
while (again[0] != 'y' && again[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Do you have any more wages. (y or n)");
gets_s(again);
}
}
while (again[0] == 'y')
{
printf("\n Enter Wages: ");
gets_s(buffer);
wages = atof(buffer);
total_wages = wages + total_wages;
printf("\n Do you have any more wages. ");
gets_s(again);
}
return total_wages;
}//end wage_loop
float other_loop()
{
char again[10];
char buffer[80];
float other_income, total_other_income = 0;
printf("\n How much in other income. ");
gets_s(buffer);
other_income = atof(buffer);
total_other_income = other_income + total_other_income;
printf("\n Do you have any more other income. (y or n)");
gets_s(again);
if (again[0] != 'y' && again[0] != 'n')
{
while (again[0] != 'y' && again[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Do you have any more other income. (y or n)");
gets_s(again);
}
}
while (again[0] == 'y')
{
printf("\n Enter other income: ");
gets_s(buffer);
other_income = atof(buffer);
total_other_income = other_income + total_other_income;
printf("\n Do you have any more other income. ");
gets_s(again);
}
return total_other_income;
}
float interest_loop()
{
char again[10];
char buffer[80];
float interest, total_interest = 0;
printf("\n How much in interest. ");
gets_s(buffer);
interest = atof(buffer);
total_interest = interest + total_interest;
printf("\n Do you have any more interest. (y or n)");
gets_s(again);
if (again[0] != 'y' && again[0] != 'n')
{
while (again[0] != 'y' && again[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Do you have any more interest. (y or n)");
gets_s(again);
}
}
while (again[0] == 'y')
{
printf("\n Enter interest: ");
gets_s(buffer);
interest = atof(buffer);
total_interest = interest + total_interest;
printf("\n Do you have any more interest. ");
gets_s(again);
}
return total_interest;
}
float dividends_loop()
{
char again[10];
char buffer[80];
float dividends, total_dividends = 0;
printf("\n How much in dividends. ");
gets_s(buffer);
dividends = atof(buffer);
total_dividends = dividends + total_dividends;
printf("\n Do you have any more dividends. (y or n)");
gets_s(again);
if (again[0] != 'y' && again[0] != 'n')
{
while (again[0] != 'y' && again[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Do you have any more dividends. (y or n)");
gets_s(again);
}
}
while (again[0] == 'y')
{
printf("\n Enter dividends: ");
gets_s(buffer);
dividends = atof(buffer);
total_dividends = dividends + total_dividends;
printf("\n Do you have any more dividends. ");
gets_s(again);
}
return total_dividends;
}//end dividends_loop
//dependants
int dependatnts_loop()
{
char again[10];
char buffer[80];
int dependants, total_dependants = 0;
printf("\n How much in dependants. ");
gets_s(buffer);
dependants = atof(buffer);
total_dependants = dependants + total_dependants;
printf("\n Do you have any more dependants. (y or n)");
gets_s(again);
if (again[0] != 'y' && again[0] != 'n')
{
while (again[0] != 'y' && again[0] != 'n')
{
printf("\n\n INCORRECT ANSWER. \n\n");
printf("\n Do you have any more dependants. (y or n)");
gets_s(again);
}
}
while (again[0] == 'y')
{
printf("\n Enter dependants: ");
gets_s(buffer);
dependants = atof(buffer);
total_dependants = dependants + total_dependants;
printf("\n Do you have any more dependants. ");
gets_s(again);
}
total_dependants = total_dependants * 2800;
return total_dependants;
}
void check_status()
{
char status[10];
int check = 0;
while (check != 1)
{
printf("What is your Status: ");
gets_s(status);
if (status[0] == 'S' && status[1] == 'H')
{
printf("\n\n CORRECT ANSWER. SH \n\n");
single_total = single_total + 1;
check = 1;
}
else if (status[0] == 'S' && status[1] == '\0')
{
printf("\n\n CORRECT ANSWER. S \n\n");
single_total = single_total + 1;
check = 1;
}
else if (status[0] == 'M' && status[1] == 'J')
{
printf("\n\n CORRECT ANSWER. MJ \n\n");
mj_total = mj_total + 1;
check = 1;
}
else if (status[0] == 'M' && status[1] == 'S')
{
printf("\n\n CORRECT ANSWER. MS \n\n");
ms_total = ms_total + 1;
check = 1;
}
else
{
printf("\n\n INCORRECT NSWER. noting \n\n");
}
}
}
float get_total_income(float wage, float div, float intre, float other, int dep)
{
char status[10];
float income = 0, sum = 0, adjusted_income = 0;
int check = 0;
sum = wage + div + intre + other;
income = sum - dep;
while (check != 1)
{
printf("\n\nWhat is your Status: ");
gets_s(status);
if (status[0] == 'S' && status[1] == 'H')
{
sh_total = sh_total + 1;
check = 1;
if (income <= 6000)
{
adjusted_income = income * 0.0;
}
else if (income > 6000 && income <= 9000)
{
adjusted_income = income * .038;
}
else if (income > 9000 && income <= 15000)
{
adjusted_income = income * .074;
}
else if (income > 15000 && income <= 21000)
{
adjusted_income = income * .110;
}
else if (income > 21000 && income <= 25000)
{
adjusted_income = income * .138;
}
else if (income > 25000 && income <= 30000)
{
adjusted_income = income * .154;
}
else if (income > 30000)
{
adjusted_income = income * .35;
}
else
{
printf("\n\n INCORRECT ANSWER. CODE IS WRONG. \n\n");
}
}
else if (status[0] == 'S' && status[1] == '\0')
{
single_total = single_total + 1;
check = 1;
if (income <= 6000)
{
adjusted_income = income * .028;
}
else if (income > 6000 && income <= 9000)
{
adjusted_income = income * .075;
}
else if (income > 9000 && income <= 15000)
{
adjusted_income = income * .096;
}
else if (income > 15000 && income <= 21000)
{
adjusted_income = income * .135;
}
else if (income > 21000 && income <= 25000)
{
adjusted_income = income * .155;
}
else if (income > 25000 && income <= 30000)
{
adjusted_income = income * .174;
}
else if (income > 30000)
{
adjusted_income = income * .35;
}
else
{
printf("\n\n INCORRECT ANSWER. CODE IS WRONG. \n\n");
}
}
else if (status[0] == 'M' && status[1] == 'J')
{
mj_total = mj_total + 1;
check = 1;
if (income <= 6000)
{
adjusted_income = income * 0.0;
}
else if (income > 6000 && income <= 9000)
{
adjusted_income = income * .052;
}
else if (income > 9000 && income <= 15000)
{
adjusted_income = income * .083;
}
else if (income > 15000 && income <= 21000)
{
adjusted_income = income * .122;
}
else if (income > 21000 && income <= 25000)
{
adjusted_income = income * .146;
}
else if (income > 25000 && income <= 30000)
{
adjusted_income = income * .163;
}
else if (income > 30000)
{
adjusted_income = income * .35;
}
else
{
printf("\n\n INCORRECT ANSWER. CODE IS WRONG. \n\n");
}
}
else if (status[0] == 'M' && status[1] == 'S')
{
ms_total = ms_total + 1;
check = 1;
if (income <= 6000)
{
adjusted_income = income * .023;
}
else if (income > 6000 && income <= 9000)
{
adjusted_income = income * .072;
}
else if (income > 9000 && income <= 15000)
{
adjusted_income = income * .089;
}
else if (income > 15000 && income <= 21000)
{
adjusted_income = income * .131;
}
else if (income > 21000 && income <= 25000)
{
adjusted_income = income * .152;
}
else if (income > 25000 && income <= 30000)
{
adjusted_income = income * .172;
}
else if (income > 30000)
{
adjusted_income = income * .35;
}
else
{
printf("\n\n INCORRECT ANSWER. CODE IS WRONG. \n\n");
}
}
else
{
printf("\n\n INCORRECT STATUS. Enter (S, MJ, MS, or SH) \n\n");
}
}
printf("\n\n\n\t YOUR WAGES: %.2f", wage);
printf("\n\t YOUR OTHER INCOME: %.2f", other);
printf("\n\t YOUR DIVIDENS: %.2f", div);
printf("\n\t YOUR INTEREST: %.2f", intre);
printf("\n\t YOUR INCOME AFTER DEPENDANTS: %.2f", income);
return adjusted_income;
}
struct
? 2. Have you learned about passing pointers to functions? (Example:void some_fun(int *store_value_here) { *store_value_here = 42; }
) \$\endgroup\$