Thread: calculate fractions

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    calculate fractions

    I wand to find a program that calculates the sum of fractions:
    1/1 + ½ +1/3 +1/4 + 1/5 + .. + 1/100

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Why not write the program yourself?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Do you have an actual question or are you hinting that your web-search-fu skills need some help?
    "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

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    If that's all you want, then you can do it in a simple spreadsheet program.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    "find" a program?
    Have you tried looking down the back of the settee, or perhaps underneath the bed?

    Announcements - C Programming
    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.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Use a for loop

    Code:
    for (int denom=1; denom <= 100; denom++) {
    // TODO
    }
    In the TODO part you should be able to "find" a statement such that your sum variable is updated to a new sum based on the current value of denom.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    21
    What do you mean "find" a program? Are you trying to find someone to write a program for you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with fractions in C++
    By Agnes Roguska in forum C++ Programming
    Replies: 43
    Last Post: 02-19-2012, 05:26 PM
  2. Fractions are just = to 0
    By Macca in forum C Programming
    Replies: 1
    Last Post: 05-10-2011, 05:41 AM
  3. fractions
    By joeshmoe1337 in forum C Programming
    Replies: 21
    Last Post: 09-11-2004, 01:34 AM
  4. Fractions
    By Aakash Datt in forum C++ Programming
    Replies: 8
    Last Post: 04-30-2003, 07:36 PM
  5. Fractions
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2002, 07:51 AM