Results 1 to 11 of 11
  1. #1
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127

    [help] basic code

    ok well i uploaded a video on to youtube so that you can look at it and tell me why 9 / 2 is not outputting 4.5.

  2. #2
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    x = (float)9 / 2;

  3. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Lol. I'll let some else handle this one, I've got to go to bed. If no one gets it by tomorrow, I'll give the answer.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  4. #4
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by why06 View Post
    Lol. I'll let some else handle this one, I've got to go to bed. If no one gets it by tomorrow, I'll give the answer.
    a bit slow lol.

  5. #5
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Just try :
    double x;
    x= 9/2;

    that should help

  6. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Not slow... no one has provided the right anser yet.

    Try 4.0/9.0

    C++ will usually assume integer data type when you type a number. The decimal point or "floating point" will make the compiler treat ur number as a float. Simply casting it will still only get you the same answer as kibble.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  7. The Following User Says Thank You to why06 For This Useful Post:

    kibbles18 (08-31-2010)

  8. #7
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    x = 9.0f/2.0f
    Ah we-a blaze the fyah, make it bun dem!

  9. The Following 3 Users Say Thank You to Hell_Demon For This Useful Post:

    kibbles18 (08-31-2010),Melodia (08-31-2010),mmbob (08-31-2010)

  10. #8
    Kallisti Version 2.0's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    44
    Reputation
    9
    Thanks
    3
    My Mood
    Amused
    Use decimals when declaring floats

  11. The Following User Says Thank You to Kallisti Version 2.0 For This Useful Post:

    kibbles18 (08-31-2010)

  12. #9
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543
    If u use simple number, the answer will be a simple number. If you use a decimal number, the answer will be a decimal number.

  13. The Following User Says Thank You to Gab For This Useful Post:

    kibbles18 (08-31-2010)

  14. #10
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    ok ty for all who helped me and told me to use decimels, it worked. i had assumed the compiler would make x 4.5 as defualt, an because the x is an int, it would just cut off the .5 part unless floated

  15. #11
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by why06 View Post
    Not slow... no one has provided the right anser yet.

    Try 4.0/9.0

    C++ will usually assume integer data type when you type a number. The decimal point or "floating point" will make the compiler treat ur number as a float. Simply casting it will still only get you the same answer as kibble.
    Quote Originally Posted by freedompeace View Post
    x = (float)9 / 2;
    Last I checked, 9.0, 9.0f and casting 9 as a float do the same thing. (I've never checked, but meh)

    <.<

Similar Threads

  1. Replies: 14
    Last Post: 10-04-2009, 02:49 PM
  2. [ HELP ] stamina code
    By ilovepie21 in forum Visual Basic Programming
    Replies: 1
    Last Post: 02-28-2008, 03:35 AM
  3. Help With Coding Please
    By pbguy145 in forum WarRock - International Hacks
    Replies: 1
    Last Post: 10-10-2007, 06:52 PM
  4. [Help] Verification Code
    By leiva1 in forum WarRock Korea Hacks
    Replies: 4
    Last Post: 05-30-2007, 06:46 AM
  5. [Help] Verification Code
    By leiva1 in forum WarRock Korea Hacks
    Replies: 5
    Last Post: 05-17-2007, 04:04 AM