Thread: Adding problem

  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,336
    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
    404
    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, 06:12 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Major Problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 01:06 PM