在 C++ 中。三角形区域是否显示为零???为什么?
In C++ .is triangle area showing zero??? why?
三角形的面积在输出中显示为零,这是为什么?
我做错了什么??
#include <iostream>
using namespace std;
int main() {
int Base, Height, Area;
// >>> Is anything wrong with the formula??
Area = (0.5) * Height * Base;
cout << "To find the Area of Triangle" << endl << endl;
// Base
cout << "Enter Base length:";
cin >> Base;
cout << endl;
// Height
cout << "Enter Height length";
cin >> Height;
cout << endl << endl;
cout << "Your Base Length is:" << Base << endl;
cout << "Your Height Length is:" << Height << endl;
// calculating area of triangle
// >>> This is the part output is zero
cout << "Area of the triangle is :" << Area << endl;
}
当您有一个计算值时,您必须计算它并对所涉及的值进行任何更改。不像代数,其中 x = y * 2
表示“x
根据定义是 y
的两倍”,在 C++ 中它表示“将 y
的值赋给 x
乘以 2
现在就这样”,对未来没有影响。
对于计算的东西,您使用函数:
int Area(const int Height, const int Base) {
return 0.5 * Height * Base;
}
现在可以在哪里调用它:
cout<<"Area of the triangle according to your measurements is :"<<Area(Height, Base)<<endl<<endl;
三角形的面积在输出中显示为零,这是为什么?
我做错了什么??
#include <iostream>
using namespace std;
int main() {
int Base, Height, Area;
// >>> Is anything wrong with the formula??
Area = (0.5) * Height * Base;
cout << "To find the Area of Triangle" << endl << endl;
// Base
cout << "Enter Base length:";
cin >> Base;
cout << endl;
// Height
cout << "Enter Height length";
cin >> Height;
cout << endl << endl;
cout << "Your Base Length is:" << Base << endl;
cout << "Your Height Length is:" << Height << endl;
// calculating area of triangle
// >>> This is the part output is zero
cout << "Area of the triangle is :" << Area << endl;
}
当您有一个计算值时,您必须计算它并对所涉及的值进行任何更改。不像代数,其中 x = y * 2
表示“x
根据定义是 y
的两倍”,在 C++ 中它表示“将 y
的值赋给 x
乘以 2
现在就这样”,对未来没有影响。
对于计算的东西,您使用函数:
int Area(const int Height, const int Base) {
return 0.5 * Height * Base;
}
现在可以在哪里调用它:
cout<<"Area of the triangle according to your measurements is :"<<Area(Height, Base)<<endl<<endl;