Skip to content

Instantly share code, notes, and snippets.

@jnikolak
Last active October 12, 2017 08:21
Show Gist options
  • Save jnikolak/9305d9a8f0848f22b236b03290482d99 to your computer and use it in GitHub Desktop.
Save jnikolak/9305d9a8f0848f22b236b03290482d99 to your computer and use it in GitHub Desktop.
Calculate Australian Tax in C
#include <stdio.h>
/* Australian Tax Rates verified with https://www.ato.gov.au/Calculators-and-tools/Host/?anchor=STC&anchor=STC#STC/questions */
int myearnings(void);
int main()
{
int unsigned long earnings,tax1,tax2,tax0;
int unsigned deftax[] = {0,3572,19822};
for (;;)
{
printf("How much do you earn?\n");
earnings=myearnings();
tax0 = (earnings-18201)*.19+deftax[0];
tax1 = (earnings-37001)*.325+deftax[1];
tax2 = (earnings-87000)*.37+deftax[2];
if(earnings<18200) {
printf("Try again, earnings less than 18200\n");
scanf("%lu",&earnings);
if(earnings<18200)
printf("Sorry exiting program, run again if you want to recalculate");
break;
}
else if(earnings<=37000)
printf("You will get taxed $%d.\nSo for the year you will earn $%d\n",tax0,earnings-tax0);
else if(earnings<=87000)
{
printf("\nYou will get taxed $%d.\nSo for the year you will earn $%d\n",tax1,earnings-tax1);
printf("That means that you will earn $%d fortnightly or $%d weekly\n",(earnings-tax1)/26,(earnings-tax1)/52);
}
else if(earnings>87000)
{
printf("You will get taxed $%d.\nSo for the year you will earn $%d\n",tax2,earnings-tax2);
}
printf("\npress \"cntrl c\" to exit, or enter another amount!\n\n");
}
return(0);
} /* Main */
int myearnings(void)
{
long unsigned int a;
scanf("%d",&a);
return(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment