hi,
i was wondering if someone could help me make a number generator. By that i mean have it start from 0 then go 00 then 000 and so on until lets five zeros(00000) and after that make it change the last number by 1. Any help would be appreciated, thanks in advance

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by firstPerson

hi,
i was wondering if someone could help me make a number generator. By that i mean have it start from 0 then go 00 then 000 and so on until lets five zeros(00000) and after that make it change the last number by 1. Any help would be appreciated, thanks in advance

can you be a bit more specific, like what kind of data structure do you use ?

I don't even understand the output you are looking for?

Can you make a list of the first 11 numbers you would like to output?

Why would you want to do this is beyond my feeble understanding. But is this the output
you were thinking of?

``````#include <iostream>
#include <string>
#include <sstream>
using namespace std;

template<typename R, typename T>
R castTo(const T& arg){
stringstream ss;
ss << arg;
R val = R();
ss >> val;
return val;
}
class MySequence{
string curr;
int cntr;
int incrementValue;
public:
MySequence() : curr(), cntr(0), incrementValue(1){}
explicit MySequence(int incr) : curr(), cntr(0), incrementValue(incr){}
string nextVal(){
if(curr.length() < 5)
curr.push_back('0');
else{
cntr += incrementValue;
string val = castTo<string>(cntr);
int end = curr.size() - val.size();
//protect against overflow
if(end < 0) {
curr = "0" + curr;
end = curr.size() - val.size();
}
string newSeq = curr.substr(0,end) + val;
curr = newSeq;
}
return curr;
}
};
int main(){
MySequence s;
for(int i = 0; i < 100; ++i){
cout << s.nextVal() << endl;
}
}``````

darn double post. Well this post is useless. Maybe there will be something here that you
would find useful. But I doubt that anything in this post will be useful to you, whoever you
are. Well, at least I made this post worth something, in my opinion of course. So anyone here doing
anything interesting projects or whatever? I tried to make the most of this post. Well thank you for
reading and wasting a few minutes or seconds of your life. Goodbye.

Edited by firstPerson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.