mardi 29 janvier 2019

Problem in my IF Statement, the Else is not working right

My simple code just receive the income from the user and calculate which bracket a user is in.

The IF statement is working fine, but when the user input some value with two decimals (ex. 100.50) value the code output the right tax and the else statement.

What can I do to fix it?

#include <iostream>
#include <iomanip>
using namespace std;

/**********************************************************************
 * This function will calculate which tax bracket a user is in.
 ***********************************************************************/
bool computeTax(float income)
{
   if (income >= 0.00 &&  income  <= 15100.00)
      cout << "10%" << endl;
   if (income > 15100.00 &&  income <= 61000.00)
      cout << "15%" << endl;
   if (income > 61300.00 &&  income <=123700.00)
      cout << "25%" << endl;
   if (income > 123700 && income <= 188450.00)
      cout << "28%" << endl;
   if (income > 188450.00 && income <= 336550.00)
      cout << "33%" << endl;
   if (income > 336550.00)
      cout << "35%" << endl;
   else
      cout << "Please enter a valid value" << endl;
   return 0;
}
int main()
{
   // configure the output to diplay money
   cout.setf(ios::fixed); // no scientific notation except for the deficit
   cout.setf(ios::showpoint); //always show the decimal point
   cout.precision(2); // two decimal for cents

   float income;
   cout << "Please enter your income: ";
   cin >> income;
   computeTax(income);
   return 0;
}

Aucun commentaire:

Enregistrer un commentaire