C Beginner - Need Help

This is a discussion on C Beginner - Need Help within the C Programming forums, part of the General Programming Boards category; Hey everyone. I'm new to this site as well as I am C Programming. My instructor is moving pretty quick ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    79

    C Beginner - Need Help

    Hey everyone. I'm new to this site as well as I am C Programming. My instructor is moving pretty quick so I'm getting lost in some things that we're learning. If anyone can help me figure this out, it would be much appreciated.

    "1. Write a C Function named as sumIntegralDigitVersionAYourName() that will ask the user for a floating point-point value and will

    a. Print the sum of the 1-digit and the 100-digit of the integral part, and
    b. Return the sum of the 1-digit and the 100-digit of the integral part.

    2. Write a C function named as sumFractionalDigitVersionAYourName() that will ask the user for a floating-point value and will then

    a. Print the sum of the first-most-significant digit and the third-most-significant digit of the fractional (decimal) part, and
    b. Return the sum of the first-most-significant digit and the third-most-significant digit of the fractional (decimal) part

    3. Write a C program with main() calling the above 2 functions; name your program as cis26Fall2010YourNameProblem5.c and also provide a sample output of your program. "


    It's not that I have a problem with the proper syntax or anything. It's more that I don't know how to use code to find the decimal parts, significant digit, etc. I'd appreciate any help.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Do you have examples of input + expected output?

    Normal double variables typically have 15 decimal digits of precision, so I don't know where this 100-digit idea is coming from.

    If you're looking at say
    1234556789009496365726524504869727294025.093579267 9257295729525 (only much larger)
    then you need to be looking at string processing.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    sumIntegralDigitVersionAYourName()
    cis26Fall2010YourNameProblem5.c
    I think your tutor failed the 'naming coventions 01' course myself mate, them's some ugly headache-inducers right there.

    Why don't you post up any code you have already, you will get more help

    EDIT:

    so I don't know where this 100-digit idea is coming from.
    Maybe it refers to the second 0 after decimal point? Apart from that the question is not exactly clear
    Last edited by rogster001; 10-13-2010 at 06:37 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    I'll use the number 123.456 as an example. The 1 = the "1-digit", the 3 = "100-digit", the 4 = the "first-most-significant-digit", the 6 = "the third-most-significant-digit". Yeah, my instructor makes this quite confusing with the names he has for the functions but... there's not much I can do.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by .C-Man. View Post
    I'll use the number 123.456 as an example. The 1 = the "1-digit", the 3 = "100-digit", the 4 = the "first-most-significant-digit", the 6 = "the third-most-significant-digit". Yeah, my instructor makes this quite confusing with the names he has for the functions but... there's not much I can do.
    Sounds like your instructor has more than that to work on...

    In the number 123.456

    The "1 digit" is the 3, not the 1.
    The "100 digit" is the 1 not the 3.

    It's hundreds, tens, ones ... not the other way around.

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Quote Originally Posted by CommonTater View Post
    Sounds like your instructor has more than that to work on...

    In the number 123.456

    The "1 digit" is the 3, not the 1.
    The "100 digit" is the 1 not the 3.

    It's hundreds, tens, ones ... not the other way around.
    That's right. I think I misread my own question myself, lol. Anyway, I don't know how to find any of those digits. This is all confusing for me.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok, let me give you one hint and you can take it from there...

    int x = (int)(( y / 100) % 100 );

    Should split out the hundreds digit for you.

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Quote Originally Posted by CommonTater View Post
    Ok, let me give you one hint and you can take it from there...

    int x = (int)(( y / 100) % 100 );

    Should split out the hundreds digit for you.
    Well it should be int x = (int)(( y / 100) % 10 ); actually because if I typed in a number like 1234.123 it would print 12 as the hundred digit. But you really helped me understand that, thanks.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Hmmmmm.... You're right and you're welcome. LOL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ADO.NET in VS2008 or gdi+ (beginner question)
    By robgar in forum C# Programming
    Replies: 3
    Last Post: 10-04-2009, 02:40 AM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 10:21 AM

Tags for this Thread


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