Writing a Vecotor list to infinity function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Writing a Vecotor list to infinity function

How do I write function that writes 1,2,3... infinitely in a vector and pass that vector. Please also check my commented code to get the scope of what i'm trying to do in https://code.sololearn.com/cpRT00RphlfH/#cpp

1st May 2020, 6:21 PM
Octopus George
Octopus George - avatar
1 Answer
0
I'm not sure I fully understand what you're trying to do, so you can correct me if I'm wrong. What I think you're trying to do is fill a vector with numbers up to a certain range, then you want to calculate the sum of all those numbers in the vector? There are many ways of getting any number of inputs, one is to define the limit yourself, the other is to have an infinite loop that ends when the numbers contains a sentinel value, another one might be to first ask the user how many numbers to input. Maybe something like this: https://code.sololearn.com/cbMtCOxBb7x9/#cpp
1st May 2020, 10:57 PM
Damyian G
Damyian G - avatar