Thread: beginner with a dumb question

  1. #1
    Unregistered
    Guest

    beginner with a dumb question

    float answer;

    //How do I get answer to be decimal


    answer = 10 - 2/5 - 8/5 - 3/8;

    cout<<answer;




    //endl;

    return 0;

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    cout<<(int)answer;
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Unregistered
    Guest

    that dont work

    that dont work me son

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hmmm. I just answered a similar question. But here you go anyway.

    cout << (float)answer;

    but you may also want to do your operations like this:
    Code:
    float answer;
    answer = 10 - 2.0/5.0 - 8.0/5.0 - 3.0/8.0;

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    master, the reason you just answered a similar questioned is because i was going to answer this post, and found that i had no idea either!

    but anyway, you shouldn't have to put:

    Code:
    cout << (float)answer << endl;
    the (float) type casting is not necessary, but if you still cant do it that way just use double instead
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I see that the cycle of life has been completed then Anyway, I'm not too sure way the 2f/5f thing didn't work for you. I'm using mingw though. I don't know why something like that would make a difference. Oh well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very dumb question.
    By Blips in forum C++ Programming
    Replies: 14
    Last Post: 11-08-2005, 09:37 AM
  2. Dumb question
    By dragon2309 in forum C Programming
    Replies: 18
    Last Post: 10-29-2005, 03:27 PM
  3. beginner question
    By Barrot in forum C++ Programming
    Replies: 4
    Last Post: 08-19-2005, 02:17 PM
  4. Question About External Files (Beginner)
    By jamez05 in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 07:05 AM
  5. dumb question...
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-28-2002, 10:35 AM