Simple math question.

I just started taking a class in C++ at school and had a quick nooby question. What happens to the remainders and decimals when you execute simple math? why does 10 / 4 = 2 rather then 2.5?


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
#include<iostream>

using namespace std;

int main()
{
	int a = 10.000, b = 4.000;
	int c;
	double d, e;
	double f = 4.00;
    char g = 'A';
	
	

	c = a % b;
	d = a / b;
	e = a / b;
	a = a + d;
	b = -d;
	g = g + 1;

	cout << "C " << c;
	cout << "D " << d;
	cout << "E " << e;
	cout << "A " << a;
	cout << "B " << b;
	cout << "G " << g;

}
Last edited on
Do you understand the meaning of double and int in the above code?
See tutorial on data types.
http://www.cplusplus.com/doc/tutorial/variables/
Topic archived. No new replies allowed.