Algorithm
Taxes
By Neilor Tonin, URI Brasil
In an imaginary country called Lisarb, all the people are very happy to pay their taxes because they know that doesn’t exist corrupt politicians and the taxes are used to benefit the population, without any misappropriation. The currency of this country is Rombus, whose symbol is R$.
Read a value with 2 digits after the decimal point, equivalent to the salary of a Lisarb inhabitant. Then print the due value that this person must pay of taxes, according to the table below.
Remember, if the salary is R$ 3,002.00 for example, the rate of 8% is only over R$ 1,000.00, because the salary from R$ 0.00 to R$ 2,000.00 is tax free. In the follow example, the total rate is 8% over R$ 1000.00 + 18% over R$ 2.00, resulting in R$ 80.36 at all. The answer must be printed with 2 digits after the decimal point.
Input
The input contains only a float-point number, with 2 digits after the decimal point.
Output
Print the message "R$" followed by a blank space and the total tax to be payed, with two digits after the decimal point. If the value is up to 2000, print the message "Isento".
Input Samples | Outputs Samples |
3002.00 |
R$ 80.36 |
1701.12 |
Isento |
4520.00 |
R$ 355.60 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
float n, r, f1, f2, f3;
scanf("%f", &n);
if(n <= 2000) {
printf("Isenton">;
} else{
if(n > 2000 && n <= 3000) {
f1 = n - 2000;
f1 = ((f1 * 8) / 100>;
r = f1;
} else if(n > 3000 && n <= 4500) {
f1 = n - 2000;
f2 = f1 - 1000;
f1 -= f2;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
r = f2 + f1;
} else {
f1 = n - 2000;
f2 = f1 - 1000;
f3 = f2 - 1500;
f1 -= f2;
f2 -= f3;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
f3 = ((f3 * 28) / 100);
r = f3 + f2 + f1;
}
printf("R$ %.2fn", r>;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float n, r, f1, f2, f3;
cin >> n;
if(n <= 2000> {
cout << "Isento" << endl;
} else {
if(n > 2000 && n <= 3000){
f1 = n - 2000;
f1 = ((f1 * 8) / 100>;
r = f1;
} else if(n > 3000 && n <= 4500) {
f1 = n - 2000;
f2 = f1 - 1000;
f1 -= f2;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
r = f2 + f1;
} else {
f1 = n - 2000;
f2 = f1 - 1000;
f3 = f2 - 1500;
f1 -= f2;
f2 -= f3;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
f3 = ((f3 * 28) / 100);
r = f3 + f2 + f1;
}
cout << "R$ " << fixed << setprecision(2> << r << endl;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
float n, r, f1, f2, f3;
Scanner sc =new Scanner(System.in);
n = sc.nextFloat();
if(n <= 2000) {
System.out.print("Isenton">;
} else {
if(n > 2000 && n <= 3000) {
f1 = n - 2000;
f1 = ((f1 * 8) / 100>;
r = f1;
} else if(n > 3000 && n <= 4500) {
f1 = n - 2000;
f2 = f1 - 1000;
f1 -= f2;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
r = f2 + f1;
} else {
f1 = n - 2000;
f2 = f1 - 1000;
f3 = f2 - 1500;
f1 -= f2;
f2 -= f3;
f1 = ((f1 * 8) / 100);
f2 = ((f2 * 18) / 100);
f3 = ((f3 * 28) / 100);
r = f3 + f2 + f1;
}
System.out.printf("R$ %.2fn",r>;
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
salario = float(raw_input())
if(salario > 0 and salario <= 2000>:
print "Isento"
elif(salario > 2000 and salario <= 3000>:
resto = salario - 2000
resultado = resto * 0.08
print "R$ %.2f" %resultado
elif(salario > 3000 and salario < 4500):
resto = salario - 3000
resultado = (resto * 0.18) + (1000 * 0.08)
print "R$ %.2f" %resultado
else:
resto = salario - 4500
resultado = (resto * 0.28) + (1500 * 0.18) + (1000 * 0.08>
print "R$ %.2f" %resultado
Copy The Code &
Try With Live Editor
Input
Output