Storing new values from a while loop?? C++ -
this question has reply here:
using unique dynamic variable names (not variable values!) 4 answersim not sure if asked question before couldn't find in search,
im using normal while loop generates series of numbers , want store these numbers int variable each, here code far
int numvalue = 30; while (numvalue<100){ numvalue= numvalue + 10; cout << numvalue<< endl; }
output: 40 50 60 70 80 90 100
so need store each output int variable , assign names automatically , how should go this?
variables statically defined cannot create names them code in loop.
but can create lists of values. in case using std::vector best choice:
#include <vector> int value = 30; std::vector<int> values; while (numvalue<100){ numvalue= numvalue + 10; values.push_back(numvalue); cout << numvalue<< endl; }
so after loop values contain 7 values. values[0] 40, values[1] 50, etc.
c++ while-loop increment
No comments:
Post a Comment