Hey if I have a value that was p=3 in a for loop, and after a few loops it gets changed to p=6 is there anyway to say "go back to previous value"?
GhostMonkey
0
Light Poster
Recommended Answers
Jump to PostSure, just store the previous value somewhere and assign it to p when you want to go back.
Jump to PostThe value is irrelevant, only the timing matters:
#include <cstdlib> #include <iostream> int main() { bool saved = false; int curr, prev; int opt; for (int i = 0; i < 10; i++) { curr = std::rand(); std::cout<<"1) Save\n2) Restore\n3) Do nothing\n> "; if (!(std::cin>> opt)) break; …
All 8 Replies
Narue
5,707
Bad Cop
Team Colleague
GhostMonkey
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
GhostMonkey
0
Light Poster
GhostMonkey
0
Light Poster
Arbus
25
Practically a Master Poster
GhostMonkey
0
Light Poster
L7Sqr
227
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.