Last active
March 2, 2021 11:55
-
-
Save cmarchena/0a19ea91c0a7fd4d2d31ee49168412cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
/* Desde 0 € hasta 12.450 € 19% | |
Desde 12.450 € hasta 20.200 € 24% | |
Desde 20.200 € hasta 35.200 € 30% | |
Desde 35.200 € hasta 60.000 € 37% | |
Desde 60.000 € hasta 300.000 € 45% | |
Más de 300.000 € 47% */ | |
float data[6][3] ={ | |
{'A', 0, 0.19}, | |
{'B', 12450, 0.24}, | |
{'C', 20200, 0.30}, | |
{'D', 35200, 0.37}, | |
{'E', 60000, 0.45}, | |
{'F', 300000, 0.47}, | |
}; | |
class IRPFCalc{ | |
long double base_imponible, acumulado =0, sustraendo, i, subtotal; | |
int determine_rate(int base_imponible){ | |
return (base_imponible >300000) ? 5 : | |
(base_imponible >= 60000 && base_imponible <= 300000) ? 4 : | |
(base_imponible >= 35200 && base_imponible <= 60000) ? 3 : | |
(base_imponible >= 20200 && base_imponible <= 35200) ? 2 : | |
(base_imponible >= 12450 && base_imponible <= 20200) ? 1 : | |
(base_imponible >= 0 && base_imponible <= 12450) ? 0 : 99; | |
} | |
public: | |
void start(){ | |
std::cout << "Bienvenido a la calculadora IRPF\n"; | |
std::cout << "Ingresa base imponible\n"; | |
std::cin >> base_imponible; | |
std::cout << "Para la base imponible de "<< base_imponible | |
<< " euros: "<< std::endl; | |
int x= determine_rate(base_imponible); | |
for(int i =0; i<= x; i++){ | |
sustraendo = i==x ? base_imponible - data[i][1]: | |
data[i+1][1] - data[i][1]; | |
subtotal = sustraendo * data[i][2]; | |
acumulado += subtotal; | |
std::cout << std::setprecision (2) << std::fixed | |
<< "Por el tramo " << char(data[i][0]) << " de " | |
<< sustraendo<< " estás pagando "<< subtotal | |
<< " euros (" << data[i][2]*100 << "%)" << std::endl; | |
} | |
std::cout << std::setprecision (2) << std::fixed | |
<< "Te toca pagar un total de " << acumulado << " euros." << std::endl; | |
}; | |
}; | |
int main(){ | |
IRPFCalc calc; | |
calc.start(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment