mardi 28 avril 2020

comparing two variables in c++

learning c++ and I'm sure I'm overlooking something obvious but I'm not sure why I dont get a message that i == j even though after the 3rd iteration the numbers are the same ?

This is the output:

8 is not equal to 12

9 is not equal to 11

appreciate any hints!

#include<iostream>

int main(){

   int i=8;
   int j=12; 

   for (i,j; i!=j; ++i, --j)
   {    
   if (i == j) 
        {     
         std::cout << "i = j" << "\n";   // this part doesnt work
         break;
        }
   else 

        std::cout << i <<" is not equal to " << j <<"\n"; 

   }
}

Aucun commentaire:

Enregistrer un commentaire