Game Development Reference
In-Depth Information
Last but not least, Listing 3-5 shows a modulo version of this program.
Listing 3-5. Finding the Remainder Between Two Numbers
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
cout << "Enter your first number: " << endl;
int number1 = 0;
cin >> number1;
cout << "Enter your second number: " << endl;
int number2 = 0;
cin >> number2;
int result = number1 % number2;
cout << "The remainder from dividing your second number into your first is: "
<< result << endl;
return 0;
}
We have to change the variables in Listing 3-5 to int from float as the modulo operator can only
operate on integer values.
Now that we have covered the arithmetic operators, we will take a look at relational operators.
Relational Operators
C++ allows us to compare variable values using relational operators. These operators allow us to work
out if two variables are equal, not equal, one is greater than the other, or one is less than the other.
There are also operators to work out if variables are less than or equal, and greater than or equal.
Each of these operators provides a true or false result that can be stored in a bool. C++ provides the
following relational operators:
Equality operator
Greater-than operators
Less-than operators
Equality Operators
The equals operator is == . We can use this in the following way:
bool isEqual = number1 == number2;
isEqual will contain true if number1 and number2 store the same value; otherwise it will contain false .
 
Search WWH ::




Custom Search