0
Good evening, I can not find problem in a code of my, it is an exercise of the site codewars(https://www.codewars.com/kata/sorting-on-planet-twisted-3-7), for those who do not know the site,is a site to train programming, here I’m only dealing with the inversion of 3 and 7, ex: enter a array{ 1,3,4,7,13,17}
the array should come out {1,7,4,3,17,13}
, my problem is that I can’t get the 3 to go out as 7, the result of that next function is {1,3,4,7,17,13}
, my only problem is number 3. I don’t know if my logic is wrong, or some other mistake. So I ask for your help
int* sortTwisted37(int* array, int arrayLength){
bool v;
for(int i=0;i<=arrayLength;i++){
if(array[i]<=10){
if(array[i]==7){
array[i]=array[i]-4;
v=true;
}else if(array[i]==3){
array[i]=array[i]+4;
v==true;
}
}else
v=false;
if(((array[i]-7)%10==0)&v==false){
array[i]=array[i]-4;
}else if(((array[i]-3)%10==0)&v==false){
array[i]=array[i]+4;
}
cout << array[i] << endl;
}
}
Sorry if something’s wrong, I’m new to the site
Maybe it’s interesting you [Dit] the question and describe what the function should do. You just said 3 would be 7 and vice versa, but you didn’t say what to do with this information.
– Woss
A hint and put your problem in the question title, and good also put what behavior your code should have and what you’ve tried to solve. So make it easy for anyone to help you.
– William Cézar