-6
私はプログラミングが初めてで、C++を学び始めたばかりです。私は、税金を払って人の純所得を決定するプログラムを作ろうとしています。ただし、プログラムが正常に動作しません。コンパイルして実行しますが、「年間経費」を求めて終了します。このコードには論理エラーがありますか?
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float grossIncome, expenses, adjustedGIncome, taxRate, taxAmount, netIncome; //Declaration of variables
char again = 'y';
while(again == 'y') //while loop used to rerun the program without having to recompile
{
system("reset");
cout << "\nEnter your Gross Annual Income: "; //User enters his gross income
cin >> grossIncome;
cout << "\nEnter your annual expenses: "; //User enters his annual expenses
cin >> expenses;
adjustedGIncome = grossIncome - expenses; //gross income adjusted for taxes
return adjustedGIncome;
if (adjustedGIncome >= 415050) //if and else if statements used to determine tax percentage
{
taxRate = 0.396;
return taxRate;
}
else if (adjustedGIncome >= 413350 && adjustedGIncome < 415050)
{
taxRate = 0.35;
return taxRate;
}
else if (adjustedGIncome >= 190150 && adjustedGIncome < 413350)
{
taxRate = 0.33;
return taxRate;
}
else if (adjustedGIncome >= 91150 && adjustedGIncome < 190150)
{
taxRate = 0.28;
return taxRate;
}
else if (adjustedGIncome >= 37650 && adjustedGIncome < 91150)
{
taxRate = 0.25;
return taxRate;
}
else if (adjustedGIncome >= 9275 && adjustedGIncome < 37650)
{
taxRate = 0.15;
return taxRate;
}
else
{
taxRate = 0.1;
return taxRate;
}
taxAmount = adjustedGIncome * taxRate; //tax amount determined so that the net income can be determined
netIncome = adjustedGIncome - taxAmount;
cout << "\nAdjusted Gross Income: " << adjustedGIncome; //displays adjusted gross income
cout << "\nTax Rate: " << taxRate; //displays tax rate depending on adjusted gross income
cout << "\nTax Amount: " << taxAmount; //displays tax amount
cout << "\n\nNet Income: " << netIncome; //displays net income
cout << "\n\nRun this program again? (Y or N): "; //allows user to rerun program
cin >> again;
again =tolower(again);
}
system("reset");
}
あなたはreturn文を返しますreturn adjustedGIncome; – user1438832
あなたは 'return'と' break'の間で混乱し、 'return'ステートメントを誤って使用しているようです。 – Shreevardhan
なぜリセットを使用していますか? –