-1

I wrote an algorithm in C++, but I'd like to know how to update an int type variable, for example:

int a = 100;
a = a - 50;

So that the next time the program is started the variable is no longer 100 but 50 and so on. First of all I would like to know if it can be done.

int a = 100;

a = a - 50;

//now it's no longer 100 but 50; at the restart of the program it will be 100 again and I don't want that.
NickD
  • 5,937
  • 1
  • 21
  • 38

1 Answers1

1

"So that the next time the program is started " - variables exist only in the running programs memory. They are not persistent between multiple runs of an application. If you want to persist/re-use data between runs, you have to save/load the data to/from a file or other persistent storage.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70