I made this program that calculates tax for a range of salaries based on user input. Everything is working fine except for the fact that i cant seem to find a way to make the application ignore the last 3 printf's and just print an error message if the user enters a negative value. I dont want to display the last 3 printf's if the user enters a negative number, instead i want the application to just display "Error: you have entered a negative number" or something of the sort. I'm using visual studio as my compiler, and this is a C application. Help plz. And also please go easy on me its for my programming class in which we are still doing very basic stuff.
Here is the code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
float salary, tax = 0;
printf("\n\n\tEnter the salary ammount per year: \t\t$");
scanf("%f", &salary);
if (salary <= 10000){
tax=0;
}
else if (salary > 10000 && salary <= 40000){
tax = (salary - 10000)*0.2;
} else if (salary > 40000 && salary <= 50000){
tax = 6000 + (salary - 40000)*0.3 ;
} else if (salary > 50000 && salary <= 75000){
tax = 9000 + (salary - 50000)*0.4;
} else if (salary > 75000.01 && salary <= 100000){
tax = 19000 + (salary - 75000)*0.5;
} else if (salary > 100000 && salary >=100000.01){
tax = 31500 + (salary - 100000)*0.6;
}
printf("\nSalary per year:\t\t $ %.2f\n\n", salary);
printf("Tax ammount per year:\t\t $ %.2f\n\n", tax);
printf("Salary after tax:\t\t $ %.2f\n", salary-tax);
getchar();getchar();
}