大家好,我需要帮助修复一个基本的c++程序。我的SurfaceArea
和我的LateralArea
收到错误。错误低于......
调用对象类型'int'不是函数或函数指针
二进制表达式的无效操作数('double'和'double')
我的代码在下面......
#include <iostream>
using namespace std; //allows me to use cout and cin w/o typing std in the main
int main(int argc, const char * argv[])
{
double height; //initialzing my variables
double bottombase;
double topbase;
double volume;
double LateralArea;
double SurfaceArea;
cout << "Please type in the height: "; //asking users for information in order to find volume, and surface area
cin >> height;
cout << "Please type in the length of one side of the bottom base: ";
cin >> bottombase;
cout << "Please type in the length of one side of the top base: ";
cin >> topbase;
volume = height * bottombase * topbase;
cout << "Your volume is: " << volume << endl;
LateralArea = 2(bottombase + topbase) * sqrt(((bottombase-topbase)/2)^2 + height^2);
SurfaceArea = LateralArea1 + bottombase^2 + topbase^2;
cout << "Your surface area is: " << SurfaceArea << endl;
return 0;
}
答案 0 :(得分:3)
您不能省略乘法运算符,因此2(bottombase + topbase)
错误,需要2 * (bottombase + topbase)
。此外,^
运算符不会执行您认为的操作。在C ++中,它是一个按位异或,很可能不是你想到的。 C ++中没有幂运算符,所以如果你必须采用某些方格,比如说x
,你应该明确x * x
或使用pow
函数:{{ 1}}。您需要pow(x, 2)
才能使用#include <cmath>
。