Thread: Wtf??? 7/9*9 = 0???

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    18

    Wtf??? 7/9*9 = 0???

    Alright I took that test on C++, I did quite well expcept
    WTF is 7/9*9 = 0 in C/C++

    I compiled this:
    Code:
    #include <iostream.h>
    int main()
    {
    	int a = 7/9*9;
    	cout<<a;
    	return 0;
    }
    HACKERS MANIFESTO (NOTE MOST WAS CUT OFF) (PEOPLE SAID IT WAS TOO LONG)
    This is our world now... the world of the electron and the switch, the beauty of the baud.
    · We make use of a service already existing withoutpaying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals.
    · We explore... and you call us criminals.
    · We seek after knowledge... and you call us criminals.
    · We exist without skin color, without nationality, without religious bias... and you call us criminals.
    · You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals.

    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

    I am a hacker, and this is my manifesto. You may stop this individual,but you can't stop us all... after all, we're all alike.
    +++The Mentor+++

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    First, something is wrong when the signature is five times as long as the post...

    You are doing integer math -- meaning all fractional parts are discarded.

    So, do each operation one at a time.

    7 / 9 = 0 (fraction is discarded for integer math)
    0 * 9 = 0.

    So 7/9*9 = 0.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    4
    exactly...

    #include <iostream.h>
    int main()
    {
    float a = 7/9*9;
    cout<<a;
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ wtf...
    By soljaragz in forum C++ Programming
    Replies: 6
    Last Post: 12-25-2006, 03:20 AM
  2. wtf...? deriving from template
    By Raven Arkadon in forum C++ Programming
    Replies: 11
    Last Post: 06-28-2005, 02:36 AM
  3. Neck bomb kills Pizza man. WTF?
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 09-03-2003, 07:40 PM
  4. wtf is wrong with msdn
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-29-2002, 05:59 PM