⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 incometaxcalculator.cpp

📁 C++大学简明教程,解压就行没有密码。希望对大家有用
💻 CPP
字号:
// Tutorial 9: IncomeTaxCalculator.cpp// Calculates a person's Federal income tax// depending on that person's salary.#include <iostream> // required to perform C++ stream I/O#include <iomanip>  // required for parameterized stream manipulatorsusing namespace std; // for accessing C++ Standard Library members// function main begins program executionint main(){   // define variables   double taxRate; // tax rate   double salary;  // yearly salary   // prompt user for and input yearly salary   cout << "\nEnter yearly salary: ";   cin >> salary; // get yearly salary   // ensure that the user entered a value greater than zero   if ( salary > 0.0 )   {      // determine appropriate tax rate based on yearly salary      switch ( static_cast< int > ( salary ) / 25000 )      {         case 0: // yearly salary under $25,000            taxRate = 0.15; // 15% tax rate            break;         case 1: // yearly salary in range $25,000-49,999         case 2: // yearly salary in range $50,000-74,999            taxRate = 0.25; // 25% tax rate            break;          case 3: // yearly salary in range $75,000-99,999         case 4: // yearly salary in range $100,000-124,999         case 5: // yearly salary in range $125,000-149,999            taxRate = 0.28; // 28% tax rate            break;          case 6:  // yearly salary in range $150,000-174,999         case 7:  // yearly salary in range $175,000-199,999         case 8:  // yearly salary in range $200,000-224,999         case 9:  // yearly salary in range $225,000-249,999         case 10: // yearly salary in range $250,000-274,999         case 11: // yearly salary in range $275,000-299,999            taxRate = 0.33; // 33% tax rate            break;         default: // yearly salary $300,000 or higher            taxRate = 0.35; // 35% tax rate      } // end switch      double incomeTax = salary * taxRate; // calculate taxes      // display income tax      cout << "\nIncome tax: $" << fixed << setprecision( 2 )         << incomeTax << endl;   } // end if   else // display error message   {      cout << "\nError: Income must be greater than 0" << endl;   } // end else   cout << "\n";   return 0; // indicate that program ended successfully} // end function main /**************************************************************************  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *  * Pearson Education, Inc. All Rights Reserved.                           *  * DISCLAIMER: The authors and publisher of this book have used their     *  * best efforts in preparing the book. These efforts include the          *  * development, research, and testing of the theories and programs        *  * to determine their effectiveness. The authors and publisher make       *  * no warranty of any kind, expressed or implied, with regard to these    *  * programs or to the documentation contained in these books. The authors *  * and publisher shall not be liable in any event for incidental or       *  * consequential damages in connection with, or arising out of, the       *  * furnishing, performance, or use of these programs.                     *  **************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -