c ++指数计算器错误

时间:2018-05-26 11:21:19

标签: c++ debugging calculator exponential

我是编程的新手,我通过制作一个计算器给自己一个挑战,但是当我想不止一次使用指数模式时,它会增加指数而不是重新启动整个事情,任何人都可以帮助我?此外,如果你有一些初学者未来项目的提示或你有一些提示,请与我分享,非常感谢! :) 这是我的代码:

int main()
{
long double num1,num2,result;
char op,redo;
result = 1;
do
{
    cout << "Give the operation! (e.g.: 2+3) aviable: + - * / ^" << endl;
    cin >> num1 >> op >> num2;
    if (op == '+' || '-' || '*' || '/' || '^') 
    {
        switch (op)
        {
            case '+':
                cout << endl << "Your solution is:" << num1 + num2;
                break;

            case '-':
                cout << endl << "Your solution is:" << num1 - num2;
                break;

            case '*':
                cout << endl << "Your solution is:" << num1 * num2;
                break;

            case '/':
                if (num2 != 0)
                {
                    cout << endl << "Your solution is:" << num1 / num2;
                }
                else
                {
                    cout << endl << "We cannot devide by 0!";
                }
                break;

            case '^':
                while (num2 != 0) {
                    result *= num1;
                    --num2;
                }

                cout << "Your solution is:" << result;
                break;

            default:
                cout << "This operation cannot be processed!";
                break;

        }
    }
    else
    {
        cout << "Wrong operation!";
    }

    cout << endl << "Would you like to restart? [Y/N]" << endl;
    cin >> redo;
} while (redo == 'y' || redo == 'Y');


return 0;
}

1 个答案:

答案 0 :(得分:1)

每次进入循环之前,您需要重置other.forEach(map -> { Object money = map.get(“money”); });

result