Class and modifiable value

I'm practicing writing classes from scratch and I'm running into an issue creating a function that does something beside get a value from a the private/protected part of the class.

When I attempt to write the fuction void program. I get that the variables must be modifiable values error. What's my problem? all my code is below.

Here's my source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include "Header.h"



void main()
{
	programMath math;
	std::cout<<math.getX()<<std::endl;
	std::cout<<math.getY()<<std::endl;
	std::cout<<math.getZ()<<std::endl;


	system("pause");

}


My header

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once


class programMath
{
protected:
	
	int x;
	int y;
	int z;

public:
	programMath();
	void program();
	int getX();
	int getY();
	int getZ();


};




My programMath.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "Header.h"

programMath::programMath()
{
		x= 5;
	y = 5;

}

void programMath::program()
{

	x+y=z;
		
}


int programMath:: getX()
{
	return x;
}


int programMath::getY()
{
	return y;
}

int programMath::getZ()
{
	return z;
}
Your problem lies in this statement.

x+y=z;

Look closely at the code it has nothing to do with the class or anything. Basically you reversed the statement from what it should be. What you are telling the compiler is that you want x + y to equal z.

What I believe you want is z = x + y;.
yes, that's exactly what I want. Sometimes the answer is so simple. Thank you
Topic archived. No new replies allowed.