Originally Posted by
Elysia
The way you've programmed it, it will not change during the life of the programme.
The statement:
int area = calculate_area();
is run once and only once during the whole life of the programme.
I suggest you remove it and call calculate_area() instead:
cout << Rectangle1.calculate_area();
That works.
Even better I set the values within calculate area as follows:
Code:
#include <iostream>
using namespace std;
class Rectangle {
public:
int length = 0;
int breadth = 0;
int calculate_area (int, int);
int calculate_perimeter (int, int);
void SetValues (int, int);
// int area = calculate_area();
};
int Rectangle::calculate_area (int First_Value, int Second_Value) {
length = First_Value;
breadth = Second_Value;
return length * breadth;
}
void Rectangle::SetValues (int First_Value, int Second_Value) {
length = First_Value;
breadth = Second_Value;
}
int main () {
Rectangle Rectangle1;
//Rectangle1.SetValues(5, 5);
cout << Rectangle1.calculate_area(4, 5);
return 0;
}