Dzefri
October 1, 2017, 4:44pm
1
I made this function to make simple "if" functions easyer to use in my code but I can't get it to work, can someone help me?
void resolveParameters(){
pR(parameter2[0],60,0);
pR(parameter2[0],-1,59);
pR(parameter1[0],-1,23);
pR(parameter1[0],24,0);
pR(parameter3[4],2,0);
pR(parameter3[4],-1,1);
pR(parameter3[5],2,0);
pR(parameter3[5],-1,1);
pR(parameter2[1],0,12);
pR(parameter2[1],13,1);
}
void pR(int a,int b,int c){
if(a == b){
a=c;
}
}
In what way does it not work, exactly?
Dzefri
October 1, 2017, 4:53pm
3
"If" function does not trigger at all, for example if "a==b", "a" stays unchanged, but it should be "a=c".
First I uset this code and it worked.
void resolveParameters(){
if(parameter2[0] == 60){//
parameter2[0]=0;
}
if(parameter2[0] == -1){//
parameter2[0]=59;
}
if(parameter1[0] == -1){//
parameter1[0]=23;
}
if(parameter1[0] == 24){//
parameter1[0]=0;
}
if(parameter3[4] == 2){//
parameter3[4]=0;
}
if(parameter3[4] == -1){//
parameter3[4]=1;
}
if(parameter3[5] == 2){//
parameter3[5]=0;
}
if(parameter3[5] == -1){//
parameter3[5]=1;
}
if(parameter2[1] == 0){
parameter2[1]=12;
}
if(parameter2[1] == 13){
parameter2[1]=1;
}
}
But when I tryed to make it with void function it stopped working
The way you've written it, a CANNOT change. the function is passed a COPY of a, which you are changing. That copy is discarded as soon as you exit the function. If you want to change the original a, change your function to:
void pR(int &a,int b,int c){[color=#222222][/color]
if(a == b){[color=#222222][/color]
a=c;[color=#222222][/color]
}[color=#222222][/color]
}
This passes a reference to a, so the function CAN change a.
Regards,
Ray L.
Dzefri
October 1, 2017, 5:08pm
5
Thanks, you just saved me a lot of work, I am now to programing so I had no Idea what problem could be.