2016-08-23 70 views
1

嗨,大家好,我需要一些幫助修復基本的程序。我在我的SurfaceArea和我的LateralArea上收到錯誤。的錯誤是下面....需要一些修復SurfaceArea和LateralArea

稱爲對象類型「INT」不是一個函數或函數指針

無效的操作數的二進制表達(「雙」和「雙」)

我的代碼如下....

#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

'2(bottombase + topbase)'應該是'2 *(bottombase + topbase)'。 '''也是按位排他的。使用'pow'代替或者僅僅使用數字本身 –

回答

3

不能省略的乘法運算,所以2(bottombase + topbase)是錯誤的,必須2 * (bottombase + topbase)。此外,^運營商不會做你認爲它的工作。在C++中,這是一個按位異或,很可能不是你想到的。在C++中沒有電源操作符,因此如果必須採用某個東西的平方,比如x,則應該明確地使用x * x或使用pow函數,如pow(x, 2)。您需要#include <cmath>才能使用pow