Game Development Reference
In-Depth Information
cout << "Enter your second number: " << endl;
int number2 = 0;
cin >> number2;
bool result = number1 == number2;
cout << "It is "
<< result
<< " that your first number is equal your second."
<< endl;
return 0;
}
This sample application was created using Microsoft Visual Studio. The program will end very
quickly after the second value has been entered, so a good trick is to set a breakpoint on the return
line using the F9 key and to use debug mode to run the program using the F5 key.
The boolean value in this sample will be printed out as a 1 when the operation results in a true value
and 0 when the result is false.
Listing 3-7 shows a simple program using the inequality operator.
Listing 3-7. The Inequality Operator
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Enter your first number: " << endl;
int number1 = 0;
cin >> number1;
cout << "Enter your second number: " << endl;
int number2 = 0;
cin >> number2;
bool result = number1 != number2;
cout << "It is "
<< result
<< " that your first number is not equal your second."
<< endl;
return 0;
}
Listing 3-8 contains the source code for an example of the greater-than operator.
 
Search WWH ::




Custom Search