back


The Basic C++ Operators

C++ uses a specific set of arithmetic operators to do its calculations. You've used them all before except perhaps, one: the modulus operator. Here's the basic breakdown:

	
	+	Addition
	-	Subtraction
	*	Multiplication
	/	Division
	%	Modulus


	


What exactly is the Modulus? Well, it returns the remainder instead of the result of division. When you are doing division with int variables, the remainder is lost. The modulus allows you to keep the remainder in a variable. You may wonder why would anyone want to keep track of that? Some programs may require you to discover whether or not what you divide divides evenly. For example, if you were writing a program that calculated prime numbers, you'd need to know when a number divided without any remainder.


That's how you say it: seven modulo three.

Assignment: Write a program that asks the user to input a dividend and a divisor and then ouput the quotient and remainder.