about FOR - LOOP proble,

hi

i need to have s.t like this
 i know that this is not the right approach to do
however, i don't know how to get it work

thx
TOm


                        for(int cur = 0 && int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1 && cur2++)
            {            
                  //for(int T = 0; T <= 1 ; T = T + ((fc2[0] - fc1[0]) / (x2 - x1)) )
                  //{
                        int T1 = ((fc2[0] - fc1[0]) / (x2 - x1));
                        int T2 = ((fc2[1] - fc1[1]) / (x2 - x1));
                        int T3 = ((fc2[2] - fc1[2]) / (x2 - x1));

                        runX = x1 + ((x2 - x1) * cur);
                        runY = y1 + ((y2 - y1) * cur);
                  
                        runC1 = fc1[0] + ( (fc2[0] - fc1[0]) * (T1 * cur2) );                        
                        runC2 = fc1[1] + ( (fc2[1] - fc1[1]) * (T2 * cur2) );
                        runC3 = fc1[2] + ( (fc2[2] - fc1[2]) * (T3 * cur2) );
                              
                        SetPixel(runX,runY,runC1,runC2,runC3);
                  //}

            }
tom_mkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Loop header should be:

for(int cur = 0, int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1, cur2++)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waysideCommented:
>                   int T1 = ((fc2[0] - fc1[0]) / (x2 - x1));
 
Note you have a potential divide-by-zero problem here. If x2 = x1 at the start of your for loop, you will crash.
0
pb_indiaCommented:
Try this:
int T1=0,T2=0,T3=0;
for(int cur = 0, int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1, cur2++) /*Like Alex suggested*/
          {          

               if((x2-x1)>0){
                     T1 = ((fc2[0] - fc1[0]) / (x2 - x1));
                    T2 = ((fc2[1] - fc1[1]) / (x2 - x1));
                    T3 = ((fc2[2] - fc1[2]) / (x2 - x1));
                 }
              else{
                 //Do error catching and resolution.
               }
                    runX = x1 + ((x2 - x1) * cur);

                    runY = y1 + ((y2 - y1) * cur);
               
                    runC1 = fc1[0] + ( (fc2[0] - fc1[0]) * (T1 * cur2) );                    
                    runC2 = fc1[1] + ( (fc2[1] - fc1[1]) * (T2 * cur2) );
                    runC3 = fc1[2] + ( (fc2[2] - fc1[2]) * (T3 * cur2) );
                         
                    SetPixel(runX,runY,runC1,runC2,runC3);
               }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.