How to save calculated values (output of a function) in an array

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to save calculated values (output of a function) in an array



I have the following code (Data1 and Data2 are real time data):


Data1


Data2


double CVCDlg::CalculatePower()

for (q = 0 ; q < index ; q++)

Data1_m[q] = Data1[q];
Data2_m[q] = Data2[q];


for (int j = start; j <= end; j++)

answer += 0.5 * (Data1_m[j + 1] + Data1_m[j]) * (Data1_m[j+1] - Data1_m[j]);


// *C
answer *= Capacitance;
return answer;



The output of this function is the returned answer, which is the calculated power, to display the results on a GUI. I used the following:


DDX_Text(pDX, IDC_EDIT_POWER, m_power);



where


m_power = CalculatePower();



Is there a method to store the real time data of m_power in an array?


m_power





Start with returning a std::vector<double> instead of a single double.
– drescherjm
Aug 12 at 4:16






Can you show me an example please so i can build upon it.
– Badr Alafnan
Aug 12 at 17:18





Your question is unclear. CalculatePower() returns a single value. Why, and where, do you need an array of values exactly?
– Remy Lebeau
Aug 12 at 18:47


CalculatePower()





Hi, That is correct it returns a single value only. this value is displayed on a GUI via m_power. I want to save it in a text file. do not worry about the time for each loop i i will sort it out later. I tried the following code but it did not work correctly.
– Badr Alafnan
Aug 13 at 0:57






for (int q = 0; q<=32780; q++) voltage[q] = m_power; std::ofstream outfile; outfile.open("Power Data.txt", std::ios_base::app); outfile<<"Total Time"<<" "<<"Total Voltage 5 sec"<<" "<<"Frequency"<<endl; outfile << voltage[q]<<endl; outfile.close();
– Badr Alafnan
Aug 13 at 1:01









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS