【问题标题】:C++ basic calculator -C++ 基础计算器 -
【发布时间】:2015-04-12 11:31:30
【问题描述】:

我想开发一个独特的计算器。所以,我在玩它,但现在我真的对这个功能感到困惑:

//Calculate two input expressions.
@prvni - First expression.
@druhe - Second expression.
@operace - Specifies mathematical operations - addition, multiplication etc.
    int vypocti(int prvni, int druhe, char operace){

      return (prvni+operace+druhe);
    }

所以,我正在尝试使用“operace”参数作为数学函数。 (如下例所示。)

  if(dpik == '+'){
    cout<<vypocti(prvni, druhe, '+');
}

你能帮帮我吗?

【问题讨论】:

  • 你不能这样,c++ 不是脚本语言。你必须映射它来调用正确的数学运算:if(operace == '+') { return prvni + druhe; }

标签: c++ operators calculator


【解决方案1】:

πάντα ῥεῖ 的评论很有帮助:

你不能这样,c++ 不是脚本语言。你必须映射它来调用正确的数学运算:if(operace == '+') { return prvni + druhe; }

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2015-05-12
    相关资源
    最近更新 更多