需要一些修复表面积和横向面积

Need some fixing SurfaceArea and LateralArea

本文关键字:横向 表面积      更新时间:2023-10-16

嗨,伙计们,我需要一些帮助修复一个基本的c++程序。SurfaceAreaLateralArea都有误差。错误如下....

被调用的对象类型'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;
}

不能省略乘法运算符,所以2(bottombase + topbase)是错的,需要是2 * (bottombase + topbase)。此外,^操作符并不像您想象的那样。在c++中,它是位异或,很可能不是你想的那样。c++中没有幂运算符,所以如果你必须取某项的平方,比如x,你应该显式地执行x * x,或者使用pow函数:pow(x, 2)。你需要#include <cmath>来使用pow