423,350 Members | 2,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,350 IT Pros & Developers. It's quick & easy.

expression-cannot-be-used-as-a-function

P: 1
so i see this error constantly,here is my code, can someone help me please?thanks in advance
Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. using namespace std; 
  3. class area 
  4.  
  5.  public: 
  6.  float  Area ,length, width, Perimeter,sqrt,coordinates;
  7.  float P1, P2, P3, P4;  
  8.  int x1,x2,x3,x4,y1,y2,y3,y4; 
  9.  
  10.  
  11. {
  12.  
  13. P1=0; 
  14. P2=0; 
  15. P3=0; 
  16. width=1; 
  17. length=1; 
  18. coordinates=0; 
  19. Area=0; 
  20. Perimeter=0;
  21.  } 
  22.  void setcoordinates()
  23.   { 
  24.   Rectangle:
  25.    cout<<"enter value of coordinates x1,x2,x3,x4,y1,y2,y3,y4"<<endl; 
  26.    cin>>x1>>x2>>x3>>x4>>y1>>y2>>y3>>y4;
  27.     P1 = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); 
  28.     P2 = sqrt((x4 - x3)*(x4 - x3) + (y4 - y3)*(y4 - y3)); 
  29.     P3 = sqrt((x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2)); 
  30.     if (x1>0,x2>0,x3>0,x4>0,y1>0,y2>0,y3>0,y4>0)
  31.      {
  32.       cout<<"Rectangle in 1st Coordinate"<<endl;
  33.        }
  34.         else {
  35.          cout<<"Rectangle is not in 1st coordinate"<<endl;
  36.          goto Rectangle; 
  37.          } 
  38.          if(P1!=P2) 
  39.          { 
  40.          cout<<"Rectangle is not valid"; goto Rectangle;
  41.           } 
  42.           }
  43.  
  44. void setwidth()
  45.  
  46.  
  47.  { Rectangle:
  48.   cout<<"width of rectangle: ";
  49.    width=P1; 
  50.    cout<<width; 
  51.    cout<<endl; 
  52.    if( width>20)
  53.     { 
  54.     cout<<"width is greater than 20"; 
  55.     goto Rectangle; 
  56.     } 
  57.  
  58.     else if (width <=0) 
  59.     { 
  60.     cout<<"width is equal or less than 0"<<endl;
  61.      goto Rectangle;
  62.       } 
  63.       } 
  64. void setlength()
  65.  {
  66.   Rectangle:
  67.    cout<<"length of rectangle: "; 
  68.    length=P3;
  69.     cout<<length; 
  70.     cout<<endl; 
  71. if(length>20)
  72.  {
  73.   cout<<"length is greater than 20."<<endl; 
  74.   goto Rectangle;
  75.    }
  76.     else if(length<=0) 
  77.     {
  78.      cout<<"length is equal or less than 0."<<endl; 
  79.      goto Rectangle;
  80.       } 
  81.       }
  82.  
  83.       void calculate() 
  84.       {
  85.        Area=width*length; 
  86.        Perimeter=2*width+2*length;
  87.       }
  88.  
  89.        void show()
  90.         { 
  91.         cout<<"width and length are less than 20 and greater than 0." <<endl; 
  92.         cout<<"Area of rectangle = "<<Area<<endl;
  93.          cout<<"Perimeter of rectangle = "<<Perimeter<<endl;
  94.           if(P1=P3)
  95.            {
  96.             cout<<"it is a Square"<<endl;
  97.              } 
  98.              else
  99.               { cout<<"it is not a square";
  100.                }
  101.                 }
  102.                  };
  103.  
  104.  
  105. int main()
  106.  {
  107.   Rectangle: 
  108.   area c; 
  109.   c.setcoordinates();
  110.    c.setwidth(); 
  111.    c.length(); 
  112.    c.calculate();
  113.     c.show(); 
  114.     return 0; 
  115.     }
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,166
What is this:

Expand|Select|Wrap|Line Numbers
  1. {
  2.  
  3. P1=0; 
  4. P2=0; 
  5. P3=0; 
  6. width=1; 
  7. length=1; 
  8. coordinates=0; 
  9. Area=0; 
  10. Perimeter=0;
  11.  }
It's not a function. It's a declared scope so anything done between the braces is deleted at the end of the scope. Probably this is what the compiler is trying to tell you.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.