The problem in question involves an iterative process in which the object "am" changes with this process (loop). So, I need to create a "res" object that will store the results of the Tfunc function to be used in the same process in another procedure. However, I can not do that. I'm a good beginner in C ++ programming. I'm a programmer in the R language.
My operational system is ubuntu 16.04 using ide codeblocks.
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const int k = 3;
double Tfunc(double Told[k][k], double amm, int K);
int sample(int x);
int main(){
 int i, j;
 double am = 50;
 double told[k][k]{
  {1,0,0},
  {0,1,0},
  {0,0,1}
};
  double res;
  res = Tfunc(told, am, k);
  for(i=0;i<k;i++){
      for(j=0;j<k;j++){
          cout << res[i][j] << " ";
      }
      cout << "\n";
  }
  return 0;
}
double Tfunc(double Told[k][k], double amm, int K)
{
 int id1;
 int id2;
 int id3;
 id1 = sample(K);
 id2 = sample(K);
 id3 = sample(K);
 while(id2 == id3){
  id3 = sample(K);
 }
 Told[id1][id2] = Told[id1][id2] + amm;
 Told[id1][id3] = Told[id1][id3] - amm;
 return Told;
}
int sample(int x)
{
 srand(time(NULL)); //initialize the random seed
 int RandIndex = rand() % (x); 
 return RandIndex;
}
 
    