c++ - Error calculating the area of a triangle? -


i'm working on program reads base , height of triangle of triangle , reports area. here's have far:

#include<iostream> using namespace std;  // simple triangle class base , height  class triangle {  public:         double setbase(double x) { //was void changed double         base = x;     }         double setheight(double y) {         height = y;     }     double getbase() {         return base;     }     double getheight() {         return height;     }  private:     double base, height; };       double area(double, double);      int main() {          triangle isoscoles1;     isoscoles1.setbase;     isoscoles1.setheight;       cin >> isoscoles1.setheight;     cin >> isoscoles1.setbase;     double x = isoscoles1.getbase;     double y = isoscoles1.getheight;      cout << "triangle area=" << area(x,y) << endl;     system("pause>nul"); }   double area(double x, double y) {     double a;     = (x*y) / 2;          return a; } 

this error gives me:-

severity    code    description project file    line    suppression state error   c3867   'triangle::setbase': non-standard syntax; use '&' create pointer member project1    c:\users\ku\desktop\test\project1\main.cpp  50   error   c3867   'triangle::setheight': non-standard syntax; use '&' create pointer member   project1    c:\users\ku\desktop\test\project1\main.cpp  51   error   c2679   binary '>>': no operator found takes right-hand operand of type 'overloaded-function' (or there no acceptable conversion)    project1    c:\users\ku\desktop\test\project1\main.cpp  54   error   c2679   binary '>>': no operator found takes right-hand operand of type 'overloaded-function' (or there no acceptable conversion)    project1    c:\users\ku\desktop\test\project1\main.cpp  55   error   c3867   'triangle::getbase': non-standard syntax; use '&' create pointer member project1    c:\users\ku\desktop\test\project1\main.cpp  56   error   c3867   'triangle::getheight': non-standard syntax; use '&' create pointer member   project1    c:\users\ku\desktop\test\project1\main.cpp  57   

what doing wrong here?

the issue in these lines:

cin >> isoscoles1.setheight; cin >> isoscoles1.setbase; 

remember setheight , setbase member functions, not actual variables. writing this:

void dosomething(double arg) {     ... }  cin >> dosomething; // error - can't read function! 

in above case, you'd this:

double value; cin >> value; dosomething(value); 

this separates out reading value calling function.

based on that, see if can think how you'd use analogous solution solve own problem.


there's issue here, pointed out in comments. take @ these lines:

isoscoles1.setbase; isoscoles1.setheight; 

think our dosomething function. have line of code this?

dosomething; 

you can safely delete 2 lines; don't , they're causing of errors you're seeing.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -