使用浮点数表示函数

时间:2016-11-13 17:48:28

标签: c++ function

我只运行了这个代码我的zybook类,它给了我错误的答案并告诉我使用浮点数来表示函数。如何将浮点数用于平方函数。

This is the image for the output results

编辑:

抱歉造成混淆

 id |      name      | wins | losses | matches
----+----------------+------+--------+---------
  2 | Peter          |    1 |      2 |       3
  1 | Kevin          |    3 |      1 |       4
  3 | John           |      |      1 |

1 个答案:

答案 0 :(得分:1)

你的职能:

int square (int what){
 return what * what;
}

应该返回一个浮点数。当你将浮点数传递给这个函数时,它将它们作为整数返回,而不是3.3和4.4得到平方,3和4做。

你应该返回一个浮点数并改变浮点数。