Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;确定税收的程序_C++ - Fatal编程技术网

C++ C++;确定税收的程序

C++ C++;确定税收的程序,c++,C++,因此,代码应该要求用户输入他们的收入,无论他们是联合申报还是单独申报,输出总收入和所得税,然后询问用户是否希望再次申报或退出。但由于某些原因,它会迫使您在继续之前输入每个输入两次。我知道我可能在代码中遗漏了一些简单的问题,但我无法解决它。使用Visual Studio,请帮助 int main() { double income = 0; double taxRate = 0; double add = 0; double subtract = 0; do

因此,代码应该要求用户输入他们的收入,无论他们是联合申报还是单独申报,输出总收入和所得税,然后询问用户是否希望再次申报或退出。但由于某些原因,它会迫使您在继续之前输入每个输入两次。我知道我可能在代码中遗漏了一些简单的问题,但我无法解决它。使用Visual Studio,请帮助

int main()
{
    double income = 0;
    double taxRate = 0;
    double add = 0;
    double subtract = 0;
    double incomeTax = 0;
    string taxStatus = "";
    string file = "";
    string answer = "";
    top:
    cout << "\nPlease enter your income to calculate your taxes\n " << endl;
    cin >> income;
    while (!(cin >> income)) //get input
    {
        if (isdigit(income))
        {
            break;
        }

        else
        {
            //if input fails, run this
            cin.clear();
            cin.sync();
            cout << "\nSorry, that was not a valid number. Please enter a valid number\n ";
        }
    }
    cin.ignore(80, '\n');

    cout << "\nIf you will be filing singly, enter 's'. If you will be filing jointly, enter 'm'\n ";
    cin >> file;
    while (!(cin >> file)) //get input
    {
        if (file == "s" || "m")
        {
            cin.ignore(80, '\n');
            break;
        }

        else
        {
            //if input fails, run this
            cin.clear();
            cin.sync();
            cout << "\nThat is not a correct input, please enter s/m\n ";
        }
    }

        if (file == "s")
        {
            if (income <= 863)
            {
                taxRate = .022;
                subtract = 0;
                add = 0;
            }

            if (income >= 864 & income <= 2588)
            {
                taxRate = .033;
                subtract = 863;
                add = 25;
            }

            if (income >= 2589 & income <= 4313)
            {
                taxRate = .062;
                subtract = 2588;
                add = 85;
            }

            if (income > 4313)
            {
                taxRate = .075;
                subtract = 4313;
                add = 181;
            }
        }

        if (file == "m")
        {
            if (income <= 1726)
            {
                taxRate = .022;
                subtract = 0;
                add = 0;
            }

            if (income >= 1727 & income <= 5176)
            {
                taxRate = .033;
                subtract = 1726;
                add = 40;
            }

            if (income >= 5177 & income <= 8626)
            {
                taxRate = .062;
                subtract = 5176;
                add = 175;
            }

            if (income > 8626)
            {
                taxRate = .075;
                subtract = 8626;
                add = 390;
            }
        }

    incomeTax = ((income - subtract) * taxRate) + add;

    cout << "\nYour taxable income is " << income << endl;

    if (file == "s")
    {
        taxStatus = "Singly";
    }
    if (file == "m")
    {
        taxStatus = "Jointly";
    }
    cout << "\nand you are filing " << taxStatus << endl;

    cout << "\nThat means your income tax will be " << incomeTax << endl;

    cout << "\nWould you like to conduct another operation, y/n?\n ";
    cin >> answer;
    while (!(cin >> answer)) //get input
    {
        if (answer == "y")
        {
            goto top;
        }
        if (answer == "n")
        {
            break;
        }
        else
        {
            //if input fails, run this
            cin.clear();
            cin.sync();
            cout << "\nThat is not a correct input, please enter y/n. ";
        }
    }
    cin.ignore(80, '\n');

    system("PAUSE");

    return 0;
}
intmain()
{
双收入=0;
双重税率=0;
双加=0;
双减法=0;
双incomeTax=0;
字符串taxStatus=“”;
字符串文件=”;
字符串答案=”;
顶部:
不能收入;
而(!(cin>>收入))//获取输入
{
if(isdigit(收入))
{
打破
}
其他的
{
//如果输入失败,请运行此命令
cin.clear();
cin.sync();
cout文件;
while(!(cin>>文件))//获取输入
{
如果(文件==“s”| |“m”)
{
cin.忽略(80,“\n”);
打破
}
其他的
{
//如果输入失败,请运行此命令
cin.clear();
cin.sync();

你的代码中可能有一些小错误,比如:
if(file==“s”| |“m”
这是不正确的,应该是
if(file==“s”| | file==“m”)
而你有一个
&
这是一个引用,它采用变量地址或按位。你想要的是两个
&
,这意味着和
在这里,请执行以下操作:

while (!(isdigit(income))) // does after cin >> income;
{
        //if input fails, run this
        cin.clear();
        cin.sync();
        cout << "\nSorry, that was not a valid number. Please enter a valid number\n ";
        cin >> income
}

while (!(file == "s" || file == "m")) //this goes after cin >> file;
{
        cin.clear();
        cin.sync();
        cout << "\nThat is not a correct input, please enter s/m\n ";
        cin >> file;
}
while(!(isdigit(income))//在cin之后做>>收入;
{
//如果输入失败,请运行此命令
cin.clear();
cin.sync();
收入
}
而(!(file==“s”| | file==“m”)//这在cin>>文件之后;
{
cin.clear();
cin.sync();
cout>文件;
}

因此,我让它停止两次请求输入,因此感谢您的帮助。我仍然无法以美元格式输出所得税和所得税,并且在最后选择“y”时返回到程序的开头。有什么建议吗

int main()
{
    double income = 0; //double stores income input
    double taxRate = 0;//double stores tax rate
    double add = 0;//double stores value added
    double subtract = 0;//double stores value to be subtracted
    double incomeTax = 0;//double stores final income tax
    string taxStatus = "";//string stores status of single or joint
    string file = "";//string stores values of s or m
    string answer = "";//string stores values of y or n
    top:
    //asks user to input income value
    cout << "\nPlease enter your income to calculate your taxes\n " << endl;
    while (!(cin >> income)) //get input
    {
        if (isdigit(income) & income > 0)//if value is positive or numbers, exits loop
        {
            break;
        }

        else//if value is not valid, runs this
        {
            //if input fails, run this
            cin.clear();//clears line
            cin.sync();
            cout << "\nSorry, that was not a valid number. Please enter a valid number\n ";//asks user to input valid input
        }
    }
    cin.ignore(80, '\n');

    //asks user to enter whether filing singly or jointly
    cout << "\nIf you will be filing singly, enter 's'. If you will be filing jointly, enter 'm'\n ";
    while (!(cin >> file)) //get input
    {
        if (file == "s" || "m")//if input is valid, save and break loop
        {
            cin.ignore(80, '\n');
            break;
        }

        else//if value not valid, print message and repeat
        {
            //if input fails, run this
            cin.clear();
            cin.sync();
            cout << "\nThat is not a correct input, please enter s/m\n ";
        }
    }

        if (file == "s")//loop determines double values for single filing
        {
            if (income <= 863)//if income is under this value, use these settings
            {
                taxRate = .022;
                subtract = 0;
                add = 0;
            }

            if (income >= 864 & income <= 2588)//if income is between these values, use these settings
            {
                taxRate = .033;
                subtract = 863;
                add = 25;
            }

            if (income >= 2589 & income <= 4313)//if income is between these values, use these settings
            {
                taxRate = .062;
                subtract = 2588;
                add = 85;
            }

            if (income > 4313)//if income is above this value, use these settings
            {
                taxRate = .075;
                subtract = 4313;
                add = 181;
            }
        }

        if (file == "m")//sets double values if joint filing
        {
            if (income <= 1726)//if income is under this value, use these settings
            {
                taxRate = .022;
                subtract = 0;
                add = 0;
            }

            if (income >= 1727 & income <= 5176)//if income is between these values, use these settings
            {
                taxRate = .033;
                subtract = 1726;
                add = 40;
            }

            if (income >= 5177 & income <= 8626)//if income is between these values, use these settings
            {
                taxRate = .062;
                subtract = 5176;
                add = 175;
            }

            if (income > 8626)//if income is above this value, use these settings
            {
                taxRate = .075;
                subtract = 8626;
                add = 390;
            }
        }

    incomeTax = ((income - subtract) * taxRate) + add;//determines value of income tax

    cout << "\nYour taxable income is " << income << endl;//prints total income

    if (file == "s")//prints 'single' if 's' is selected
    {
        taxStatus = "Singly";
    }
    if (file == "m")//prints 'jointly' if 'm' selected
    {
        taxStatus = "Jointly";
    }
    cout << "\nand you are filing " << taxStatus << endl;//prints filing status

    cout << "\nThat means your income tax will be " << incomeTax << endl;//prints actual income tax

    cout << "\nWould you like to conduct another operation, y/n?\n ";//asks if user wants to do another filing
    while (!(cin >> answer)) //get input
    {
        if (answer == "y")//returns to start of program if yes
        {
            goto top;
        }
        if (answer == "n")//breaks loop if no
        {
            break;
        }
        else//if not valid answer, print message and run again
        {
            //if input fails, run this
            cin.clear();
            cin.sync();
            cout << "\nThat is not a correct input, please enter y/n. ";//asks user to try again
        }
    }
    cin.ignore(80, '\n');

    system("PAUSE");

    return 0;//ends program
}
intmain()
{
double income=0;//double存储收入输入
双重税率=0;//双重存储税率
double add=0;//double存储增值
double subtract=0;//double存储要减去的值
double incomeTax=0;//double存储最终所得税
string taxStatus=“”;//字符串存储单个或关节的状态
string file=”“;//字符串存储s或m的值
string answer=“;//字符串存储y或n的值
顶部:
//要求用户输入收入值
cout income()//获取输入
{
if(isdigit(income)&income>0)//如果值为正数或数字,则退出循环
{
打破
}
else//如果值无效,则运行此
{
//如果输入失败,请运行此命令
cin.clear();//清除行
cin.sync();
cout file))//获取输入
{
if(file==“s”| |“m”)//如果输入有效,保存并中断循环
{
cin.忽略(80,“\n”);
打破
}
否则//如果值无效,则打印消息并重复
{
//如果输入失败,请运行此命令
cin.clear();
cin.sync();

cout
cin>>income;
和您的其他输入行都是重复的,因此您需要输入两次也就不足为奇了。
goto
有一个位置,但这种用法很容易避免。建议将其替换。替换为什么?我无论如何都无法使末尾的循环正常工作。如何以美元格式打印它们?如果使用,请使用其中一种(文件==“s”| |“m”或if(文件==“s”| |文件==“m”)不做任何更改,实际上不检查字符串中的字符。如果你回答了自己的问题,这很好,但是如果你有其他问题,你应该单独发布。如果你的问题在解决各种问题时不断变形为新的问题,这并不是一件好事,因为它会根据原始的q生成答案无效。