Please use Code tags when posting snippets.
int MyClass::internalSum= 2+6;
Here you are assignig the value 8 to the variable "internalSum". It is never changed, so it will always return 8.
My guess is that you want the result of "add()" to be saved in "internalSum". Now, you are adding a to b in total, but total is discarded as it only exists in the
scope of the add() function. Once add() returns, total is destroyed and its value lost. Instead, try saving the result of "a + b" into the internalSum value.
Also, you have three ints: 'a', 'b' and 'c'. However, you only use one: 'b'. The naming of internalSum makes me think that your class is only supposed to carry one number (internalSum), which is manipulated via functions and printed via "display".
As a hint, here's how your main should look and what it displays:
1 2 3 4 5 6
|
MyClass mc(2);
mc.display(); // "The value is now 2"
mc.add(8);
mc.display(); // "The value is now 10"
mc.add(4);
mc.display(); // "The value is now 14"
|
The key features of the code you have to write are these:
a) "MyClass" holds one value: the current total.
b) The function add() should add the parameter value to the current total.
c) The function display() should print out the current total.
[Optional d) Outside access to variables should be restricted.]