%

What does the % do in C++

For example in my friend's program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//------------------------------------------------
#include <iostream>
#include <windows.h>
using namespace std;
//------------------------------------------------
//Main method
void main()
{
	//Number to find the multiples below
	int number = 0;
	//X and Y
	int	x = 0;
	int y = 0;
	//General index value
	int i = 0;
	//The value to be printed
	int sum = 0;
	//Present the program to the user
	cout << "This program finds the sum of all of the multiples \n";
	cout << "of x or y below z. \n";
	//Ask the user for the values
	cout << "First input the value of z: ";
	cin >> number;
	cout << "\n";
	cout << "Now x: ";
	cin >> x;
	cout << "\n";
	cout << "Now y: ";
	cin >> y;
	cout << "\n";
	//Now that we have the values, begin the loop
	while (i <= number) 
	{
		if (i % x==0) 
		{
			//i is a multiple of x
			//Add it to the sum
			sum += i;
		}
		else if (i % y==0) 
		{
			//i is a multiple of y
			//Add it to the sum
			sum += i;
		}
		//Now check the next number
		i += 1;
	}
	cout << "Sum = " + sum << endl << endl;
}	


the ifs dont work and the program jumps to the last cout, how do I fix this
x%4 for example:
1
2
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 0 1 2 3 0 1 2  3  0
Last edited on
It found itself in C++ from C by accident.:)
how do I fix this

change line 7 to:
int main()

change line 49 to:
 
    cout << "Sum = " << sum << endl << endl;
Thanks
Topic archived. No new replies allowed.