Thread: casting question

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    29

    casting question

    Hi,

    This seems a ridiculously simple problem but I can't seem to figure out whats going wrong (maybe I'm looking at it too long):

    I'm trying to cast a double to an int but I keep getting an error "syntax error: type".

    The code is really simple:

    double mn;
    int int_k;

    mn = 6.0;
    int_k = int(mn);

    What could be causing the problem?

    Thanks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    k = (int)mm;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    29
    Hi Salem,

    Thanks for that ...Can't believe that was it - my brain clearly switched off from staring at the screen.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kerrymaid View Post
    my brain clearly switched off from staring at the screen.
    So long as it doesn't go the other way around...

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I hate it when your screen turns your brain off, by staring at it too long!

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I hate it when your screen turns your brain off, by staring at it too long!
    Yeah but... like I said... it's even worse when the screen turns off after staring at your brain for to long.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Type Casting Question
    By firebird in forum C Programming
    Replies: 34
    Last Post: 08-10-2011, 09:35 PM
  2. Question on casting 0
    By laertius in forum C Programming
    Replies: 2
    Last Post: 11-09-2008, 12:15 PM
  3. question about casting
    By movl0x1 in forum C Programming
    Replies: 8
    Last Post: 07-09-2007, 09:51 PM
  4. Casting Question (I think)
    By fayte in forum C Programming
    Replies: 6
    Last Post: 03-08-2006, 05:31 PM
  5. [Newbie] Casting question
    By joeljkp in forum C Programming
    Replies: 15
    Last Post: 06-15-2004, 12:24 PM