convert char to float

This is a discussion on convert char to float within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, i'm kinda stuck with this method of converting char to float. What i'm trying to do is let ...

  1. #1
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200

    convert char to float

    Hi everyone, i'm kinda stuck with this method of converting char to float. What i'm trying to do is let the user enters the amount of money in character variable, then convert it into float variable. Please help, thanks
    Hello, testing testing. Everthing is running perfectly...for now

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    131
    Post what you have.....Why are you using a char for the input?

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Just do a search at google for "C++ ATOF"

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    The mighty stringstream is your friend.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    BTW, a char holds a single character. You probably mean to say character array or string. In which case a stringstream (or atof, or sprintf) is the way to go.

  6. #6
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Quote Originally Posted by chadsxe
    Post what you have.....Why are you using a char for the input?
    The code is use for OpenGL, the typing function use an array of character to accept the user input. That is why i have to convert from char to float. It is for default price for an object. The adminstration input a default price. Thanks
    Hello, testing testing. Everthing is running perfectly...for now

  7. #7
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Never mind guys, my problem was that i convert the string character before i enter the value, which it will automatic give a 0 value for the variable. Thank you anyway
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  3. Display list not displaying?
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 09-19-2004, 06:47 PM
  4. Repetition in do{}while
    By Beast() in forum C Programming
    Replies: 25
    Last Post: 06-16-2004, 10:47 PM
  5. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 09:14 PM

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