C++ Using a sequence of values from 'for' loop one at a time in a consecutive order within another function
up vote
-1
down vote
favorite
I would like to use a 'for' loop (OR anything that works for that matter) to generate a sequence of values.
I iterate many times and need to use values from the loop (OR anything that works) one at a time in a consequent manner. This values are used to represent 'time' value in an equation for population growth. Ultimately I am to have a chart representing solutions for calculations where 'time'is 1,2,3,4...60.
My question is: how to make the equation "value = a * exp(k * t)" consider t = 'time'as a new consecutive value from a vector that 'loop' generated ?
EDIT: I will try to clarify the set up - both reset and update act as iterations. In this specific case reset runs once and update runs n times. What I need is to use a consequent value of 'time' each iteration of update i.e. first time update runs the value of t = first value within the vector, second time update runs t = second value within the vector etc.
void ExponentialGrowth::reset() {update();}
void ExponentialGrowth::update() {value = a * exp(k * t); }
c++ loops for-loop indexing reference
add a comment |
up vote
-1
down vote
favorite
I would like to use a 'for' loop (OR anything that works for that matter) to generate a sequence of values.
I iterate many times and need to use values from the loop (OR anything that works) one at a time in a consequent manner. This values are used to represent 'time' value in an equation for population growth. Ultimately I am to have a chart representing solutions for calculations where 'time'is 1,2,3,4...60.
My question is: how to make the equation "value = a * exp(k * t)" consider t = 'time'as a new consecutive value from a vector that 'loop' generated ?
EDIT: I will try to clarify the set up - both reset and update act as iterations. In this specific case reset runs once and update runs n times. What I need is to use a consequent value of 'time' each iteration of update i.e. first time update runs the value of t = first value within the vector, second time update runs t = second value within the vector etc.
void ExponentialGrowth::reset() {update();}
void ExponentialGrowth::update() {value = a * exp(k * t); }
c++ loops for-loop indexing reference
2
Store the values from the initialfor
loop in a table - or am I missing the point?
– 500 - Internal Server Error
Nov 22 at 13:01
Iftime
is 1,2,3,4,...60, why do you need to calculate it?
– molbdnilo
Nov 22 at 13:17
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I would like to use a 'for' loop (OR anything that works for that matter) to generate a sequence of values.
I iterate many times and need to use values from the loop (OR anything that works) one at a time in a consequent manner. This values are used to represent 'time' value in an equation for population growth. Ultimately I am to have a chart representing solutions for calculations where 'time'is 1,2,3,4...60.
My question is: how to make the equation "value = a * exp(k * t)" consider t = 'time'as a new consecutive value from a vector that 'loop' generated ?
EDIT: I will try to clarify the set up - both reset and update act as iterations. In this specific case reset runs once and update runs n times. What I need is to use a consequent value of 'time' each iteration of update i.e. first time update runs the value of t = first value within the vector, second time update runs t = second value within the vector etc.
void ExponentialGrowth::reset() {update();}
void ExponentialGrowth::update() {value = a * exp(k * t); }
c++ loops for-loop indexing reference
I would like to use a 'for' loop (OR anything that works for that matter) to generate a sequence of values.
I iterate many times and need to use values from the loop (OR anything that works) one at a time in a consequent manner. This values are used to represent 'time' value in an equation for population growth. Ultimately I am to have a chart representing solutions for calculations where 'time'is 1,2,3,4...60.
My question is: how to make the equation "value = a * exp(k * t)" consider t = 'time'as a new consecutive value from a vector that 'loop' generated ?
EDIT: I will try to clarify the set up - both reset and update act as iterations. In this specific case reset runs once and update runs n times. What I need is to use a consequent value of 'time' each iteration of update i.e. first time update runs the value of t = first value within the vector, second time update runs t = second value within the vector etc.
void ExponentialGrowth::reset() {update();}
void ExponentialGrowth::update() {value = a * exp(k * t); }
c++ loops for-loop indexing reference
c++ loops for-loop indexing reference
edited Nov 23 at 12:52
asked Nov 22 at 12:59
Vladimir Alexandrovich Mishin
11
11
2
Store the values from the initialfor
loop in a table - or am I missing the point?
– 500 - Internal Server Error
Nov 22 at 13:01
Iftime
is 1,2,3,4,...60, why do you need to calculate it?
– molbdnilo
Nov 22 at 13:17
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56
add a comment |
2
Store the values from the initialfor
loop in a table - or am I missing the point?
– 500 - Internal Server Error
Nov 22 at 13:01
Iftime
is 1,2,3,4,...60, why do you need to calculate it?
– molbdnilo
Nov 22 at 13:17
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56
2
2
Store the values from the initial
for
loop in a table - or am I missing the point?– 500 - Internal Server Error
Nov 22 at 13:01
Store the values from the initial
for
loop in a table - or am I missing the point?– 500 - Internal Server Error
Nov 22 at 13:01
If
time
is 1,2,3,4,...60, why do you need to calculate it?– molbdnilo
Nov 22 at 13:17
If
time
is 1,2,3,4,...60, why do you need to calculate it?– molbdnilo
Nov 22 at 13:17
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
if t is integer type (0 to 60)
#include "math.h"
int a = 1;
int k = 2;
for(int time = 0; time < 60; ++time){
int value = a * exp(k * time);
}
if you have to pass the size juste make a function
void func(int _start, int _end){
int a = 1;
int k = 2;
for(int i = _start; i <= _end; ++i){
int value = a * exp(k * i);
}
}
In C++, the<cmath>
header would be preferred, along withstd::exp
.
– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
if t is integer type (0 to 60)
#include "math.h"
int a = 1;
int k = 2;
for(int time = 0; time < 60; ++time){
int value = a * exp(k * time);
}
if you have to pass the size juste make a function
void func(int _start, int _end){
int a = 1;
int k = 2;
for(int i = _start; i <= _end; ++i){
int value = a * exp(k * i);
}
}
In C++, the<cmath>
header would be preferred, along withstd::exp
.
– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
add a comment |
up vote
3
down vote
if t is integer type (0 to 60)
#include "math.h"
int a = 1;
int k = 2;
for(int time = 0; time < 60; ++time){
int value = a * exp(k * time);
}
if you have to pass the size juste make a function
void func(int _start, int _end){
int a = 1;
int k = 2;
for(int i = _start; i <= _end; ++i){
int value = a * exp(k * i);
}
}
In C++, the<cmath>
header would be preferred, along withstd::exp
.
– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
add a comment |
up vote
3
down vote
up vote
3
down vote
if t is integer type (0 to 60)
#include "math.h"
int a = 1;
int k = 2;
for(int time = 0; time < 60; ++time){
int value = a * exp(k * time);
}
if you have to pass the size juste make a function
void func(int _start, int _end){
int a = 1;
int k = 2;
for(int i = _start; i <= _end; ++i){
int value = a * exp(k * i);
}
}
if t is integer type (0 to 60)
#include "math.h"
int a = 1;
int k = 2;
for(int time = 0; time < 60; ++time){
int value = a * exp(k * time);
}
if you have to pass the size juste make a function
void func(int _start, int _end){
int a = 1;
int k = 2;
for(int i = _start; i <= _end; ++i){
int value = a * exp(k * i);
}
}
edited Nov 22 at 13:11
answered Nov 22 at 13:05
Skogandr
643
643
In C++, the<cmath>
header would be preferred, along withstd::exp
.
– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
add a comment |
In C++, the<cmath>
header would be preferred, along withstd::exp
.
– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
In C++, the
<cmath>
header would be preferred, along with std::exp
.– Mike Borkland
Nov 22 at 15:37
In C++, the
<cmath>
header would be preferred, along with std::exp
.– Mike Borkland
Nov 22 at 15:37
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
When you say size do you mean just as in 60 ? Because I need 60 different values.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431597%2fc-using-a-sequence-of-values-from-for-loop-one-at-a-time-in-a-consecutive-or%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Store the values from the initial
for
loop in a table - or am I missing the point?– 500 - Internal Server Error
Nov 22 at 13:01
If
time
is 1,2,3,4,...60, why do you need to calculate it?– molbdnilo
Nov 22 at 13:17
I need to calculate value not the time.
– Vladimir Alexandrovich Mishin
Nov 23 at 9:56