Hi all,
The topic is my question. I’ll explain it more. Just look at the following C++ code segment,
if(number_1 == number_2);
{
std::cout << number_1 << " == " << number_2 << std::endl;
}
Note that, I have put a semicolon just after the right parentheses. It’s not a syntax error, because at the compile time it not gives an error. So, it should be a logic error. I found that semicolon causes the body of the “if” statement to be empty, from a book. So, there can’t be a output like “5 == 5”, if my input are 5 and 5 on the following code.
#include <iostream>
//using namespace std;
int main()
{
int number_1;
int number_2;
std::cout << "Enter two numbers:\t";
std::cin >> number_1 >> number_2 ;
if(number_1 == number_2);
{
std::cout << number_1 << " == " << number_2 << std::endl;
}
if(number_1 != number_2)
{
std::cout << number_1 << " != " << number_2 << std::endl;
}
return 0;
}
So where I’m going wrong, my code or my scrap on that book explanation.