【发布时间】:2021-10-16 08:33:26
【问题描述】:
我在给出底和高时找到三角形面积的解决方案(特别要求也使用浮点类型转换的问题):
#include <iostream>
using namespace std;
int area()
{
int b=7,h=5;
float area;
area=(float)b*h/2;
return area;//Write a expression to find Area as float using typecasting
}
正确解决方案:
#include<iostream>
using namespace std;
void area()
{
int b=7,h=5;
float area;
area=(float)b*h/2;
cout<<area;
}
我的代码有什么问题?
【问题讨论】:
-
int area()你不认为你应该返回一个float吗?
标签: c++ integer return std void