I want to increase the increment by 1 each time. I want to be able to get 1, 3, 6, 10, 15, 21, 28, 36, 46...
First it adds 1 then 2 then 3 then 4 and so on and so fourth.
you could use a variable to increment your counter
for(int counter = 0, increment = 0; counter < 100; increment++, counter += increment){
...do_something...
}
int incrementer = 1;
for ( int i = 1; i < someLength; i += incrementer )
{
cout << i << endl;
++incrementer;
}
or if you want to do it in as few lines as possible (but less readable):
for ( int i = 1, inc = 1; i < 100; ++inc, i += inc )
cout << i << endl;
Output:
1
3
6
10
etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With