jeudi 28 mars 2019

How to make a variable always equal to the result of some calculations?

In math, if z = x+y/2, then z will always change whenever we replace the value of x and y. Can we do that in programming without having to specifically updating z whenever we change the value of x and y?

I mean something like that won't work, right?

int x;
int y;
int z{x + y};
cin >> x;
cin >> y;
cout << z;

Aucun commentaire:

Enregistrer un commentaire