CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Problem with program

    Hi! I want help about a problem that I can't understand what i should do!
    I want to create a program in C that will take (from a user) three integer numbers: x, y and n, and then make the count: x/y and print the result with n decimal numerals (that gave the user before).
    Has anyone an idea?

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Problem with program

    Has anyone an idea?
    Yes, a good start would to buy a book or find a good online resource for learning to program.

  3. #3
    Join Date
    Apr 2010
    Posts
    5

    Re: Problem with program

    Quote Originally Posted by jimmys View Post
    Hi! I want help about a problem that I can't understand what i should do!
    I want to create a program in C that will take (from a user) three integer numbers: x, y and n, and then make the count: x/y and print the result with n decimal numerals (that gave the user before).
    Has anyone an idea?
    Quote Originally Posted by Skizmo View Post
    Yes, a good start would to buy a book or find a good online resource for learning to program.
    i know programming well. i know how to make program that make and print the x/y result, but how it can refund n decimal numerals?? this is my question! skizmo i think that it is not very simple program, because i know well programming, but i have difficulties in this program.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Problem with program

    Quote Originally Posted by jimmys View Post
    i know programming well. i know how to make program that make and print the x/y result, but how it can refund n decimal numerals?? this is my question! skizmo i think that it is not very simple program, because i know well programming, but i have difficulties in this program.
    Your requirement isn't clear to me. What refund? What do you mean "decimal numerals"?

  5. #5
    Join Date
    Apr 2010
    Posts
    5

    Re: Problem with program

    Quote Originally Posted by GCDEF View Post
    Your requirement isn't clear to me. What refund? What do you mean "decimal numerals"?
    sorry my english is not very good. i want to make a program that if for example the user give the numbers x=5, y=7 and n=3, the program should make 5/8 and print the result: 0,714.
    With other words the variable n is the number of numerals after the " , "
    if n is 4, it should print 0,7142.
    if n=5, it should print 0,71428.
    etc.
    The program should operate even if the user give a big number, for example n=3.000.
    I tell again that the numbers that give the user are all integer.

  6. #6
    Join Date
    Apr 2010
    Posts
    5

    Re: Problem with program

    Quote Originally Posted by jimmys View Post
    if for example the user give the numbers x=5, y=7 and n=3, the program should make 5/8 and print the result: 0,714.
    sorry i would like to write 5/7.

  7. #7
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Problem with program

    Since it's plain C I have no better idea than creating the format string in code:
    Code:
    char fmt[10];
    sprintf( fmt, "%%.%df", n );
    printf( fmt, x/y );
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  8. #8
    Join Date
    Apr 2010
    Posts
    5

    Re: Problem with program

    C or C++ I dont have problem... I want simply to make this program.
    Thanks SMA! I will try it...

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Problem with program

    you can use the * formatting to handle the decimals with using printf()

    printf( "%0.*f", n, x/y);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured