Adding problem

This is a discussion on Adding problem within the C Programming forums, part of the General Programming Boards category; Hi, kind of a strange question but can anyone understand why Code: double rgbTo1 (int rgb){ return rgb/255; } with ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    101

    Question Adding problem

    Hi, kind of a strange question but can anyone understand why

    Code:
    double rgbTo1 (int rgb){
    	return rgb/255;
    }
    with the call
    Code:
     rgbTo1(240);
    can return 0?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because 240/255 is 0. (0 with remainder 240, more specifically, but you didn't ask for the remainder.)

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    If you want the decimal value to be returned, change your code to this:
    Code:
    double rgbTo1 (int rgb){
    	return rgb/255.0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding strings hard problem...
    By qubit67 in forum C Programming
    Replies: 28
    Last Post: 04-22-2007, 02:02 AM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. What's problem of adding two binary number?
    By Mathsniper in forum C Programming
    Replies: 1
    Last Post: 01-12-2007, 05:12 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  5. Major Problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 12:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21