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); }










share|improve this question




















  • 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















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); }










share|improve this question




















  • 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













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); }










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 12:52

























asked Nov 22 at 12:59









Vladimir Alexandrovich Mishin

11




11








  • 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














  • 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








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












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);
}
}





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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);
}
}





share|improve this answer























  • 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















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);
}
}





share|improve this answer























  • 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













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);
}
}





share|improve this answer














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);
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 13:11

























answered Nov 22 at 13:05









Skogandr

643




643












  • 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


















  • 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
















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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)