C++で退職積立金の源泉徴収額を計算するコードをかいてみた

code-2620118_640

今日も宿題でコードを書いてました。特筆すべきところは給与に小数が生じているのでdouble関数でかえしているところです。

// This program calculates the amount of pay that will
// be contributed to a retirement plan if 5%, 7%, or 10%
// of monthly pay is withheld.(退職積立金の源泉徴収計算)
#include <iostream>
using namespace std;

int main()
{
// Variables to hold the monthly pay and the
// amount of contribution.(一月あたりの給料)
double monthlyPay = 6000.0, contribution;

// Calculate and display a 5% contribution.(5%源泉徴収)
contribution = monthlyPay * 0.05;
cout << “5 percent is $” << contribution
<< ” per month.\n”;

// Calculate and display a 7% contribution. (7%源泉徴収)
contribution = monthlyPay * 0.07;
cout << “7 percent is $” << contribution
<< ” per month.\n”;

// Calculate and display a 10% contribution.(10%源泉徴収)
contribution = monthlyPay * 0.1;
cout << “10 percent is $” << contribution
<< ” per month.\n”;

return 0;
}

出力は以下の通りです。

5 percent is $300 per month.
7 percent is $420 per month.
10 percent is $600 per month.

徐々に難しくなってきましたがやるべきことは特に変わらないですね。あせらず一つずつできることからこなしていくのみです。

基礎からしっかり学ぶC++の教科書 C++14対応
矢吹 太朗
日経BP社
2017-02-16

ご面倒おかけしますが、たまにはクリックお願いします!

にほんブログ村 海外生活ブログ 海外移住へ
にほんブログ村

にほんブログ村 海外生活ブログへ
にほんブログ村