Is my compiler defective?

So today i got bored so i decided to write this simple code to see what happens:

1
2
3
4
int x = 7;
int y = 22;
int z = 7/22;
cout << z << endl;


Result: 0

Now my question is, since 7 divided by 22 is actually like 3.141592653589796....
so on and so on forever (If you haven't noticed yet, its "pi") why did it give me 0?




Because of the data type you are using. Try it with float/double.

Here is the good place to start reading:

http://www.cplusplus.com/doc/tutorial/variables/

OH YEAH! I forgot about floats xD (just goes to show how nooby i am T_T) thanks kevin!
And your maths is suspect - 7/22 is nowhere near 3
He meant 22/7 not 7/22.
Topic archived. No new replies allowed.