Grupo
Estructuras Condicionales Avanzadas en C++
Ojetivo
1. Solicitar al usuario que ingrese su salario como un número de punto flotante.
2. Aplicar un conjunto de reglas impositivas condicionales basadas en el rango salarial.
3. Calcular y mostrar el importe del impuesto a pagar.
Implementar un programa que calcule el impuesto a pagar según el salario.
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the input/output library
using namespace std;
int main() {
// Declare a variable to store the salary
float salary;
// Declare a variable to store the tax to be paid
float tax = 0.0;
// Prompt the user to enter their salary
cout << "Enter your salary: ";
cin >> salary;
// Apply tax rules based on salary range
if (salary <= 10000) {
// No tax for salaries up to $10,000
tax = 0;
} else if (salary <= 20000) {
// 10% tax for salaries between $10,001 and $20,000
tax = (salary - 10000) * 0.10;
} else if (salary <= 40000) {
// 10% for the first $10,000 after $10,000, and 20% for the rest
tax = (10000 * 0.10) + (salary - 20000) * 0.20;
} else {
// 10% for $10,000, 20% for $20,000, and 30% for the amount above $40,000
tax = (10000 * 0.10) + (20000 * 0.20) + (salary - 40000) * 0.30;
}
// Display the calculated tax
cout << "The tax to be paid is: $" << tax << endl;
return 0; // End of program
}
Salida
Enter your salary: 45000
The tax to be paid is: $7000
Comparte este ejercicio C++