Thread: This seemed impossible!Can anyone help??

  1. #1
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38

    This seemed impossible!Can anyone help??

    Now this is kinda beyond newbie knowledge!!! i was just wondering... What's the code for making a program that will ask the user a number and it will print out the round off of its tens value, hundreds value, thousands value up to hundred thousands value???? kinda overboard huh?

    example:
    Enter number:
    538

    1 ones 500 hundreds
    40 tens until it reaches hundred thousands...


    please tell me what to #include, what to place in the int, and the function that i will use to round off the number...
    by the way, i WILL use scanf() right?

    PLEASE!!! ONEGAI!!!!
    Last edited by nesir; 08-09-2006 at 05:34 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, you should go read the forum guidelines link at the top of the forum. In an effort to not be too abusive, I'll assume you missed it, and that you didn't actually ignore it. At any rate, you'll find that you need to make an effort, when you read that, which I know you will. Then, when you've posted your attempt, we'll nudge you in the right direction.

    You have now used up all of your 'non-abusive' points.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > i WILL use scanf() right?
    Sure, to read the number in.

    The rest is up to you and your skill at mathematics.
    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.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    X/100*100

    That should be all you need to round integers. For floating point it's more complicated and there are a number of aproaches.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    LOL @ quzah... my, u sure are scary..

  6. #6
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    okay.. here's the deal...
    Please tell me what's wrong in this code because I can't get what I want!!
    This is on how to get the tens value first... You see, if I am going to input 458
    , the output must be: Round of at Tens Value is: 1 but that's not happening! why? where did I mess up?

    #include <stdio.h>
    #include <ctype.h>
    int main(void){
    int x;
    printf("Enter a number: ");
    scanf("%d",&x);
    printf("Round of at Tens Value: %d",(x/100)*100);
    return 0;
    }
    Last edited by nesir; 08-15-2006 at 09:22 AM.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Please tell me what's wrong in this code
    Please tell us what you're expecting as the output.
    My best code is written with the delete key.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > the output must be: Round of at Tens Value is: 1
    How did you get 1 ?
    I would expect 4 or 5, but 1 ?
    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.

  9. #9
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    okay, here's the REAL DEAL. My instructor obviosly created a serious mistake... if I was to input a number, say 538, the output of its tens value must be 40... but now i can't seem to make it happen! What's wrong???

    TO ALL THOSE WITH FRIENDSTER, ADD ME!

    i'm [email protected]
    a newbie in the field of Computer Science!! Pray for all the student's success!

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Okay, if I understand you correctly, you want 538 rounded to the tens place to be 540. Rounded to the hundreds place, the value would remain 538. Rounded to the thousands place, it would become 1000?

    A simple solution would be to extract the value you want to check and then subtract it from the place. This gives you a difference. If the difference is less than half the place, add it to the value. Here's an example:
    Code:
    # Tens place
    538 % 10 == 8
    10 - 8 == 2
    10 / 2 == 5
    
    2 < 5 so
      538 + 2 == 540
    
    # Hundreds place
    538 % 100 == 38
    100 - 38 == 62
    100 / 2 == 50
    
    62 > 50 so
      no change
    
    # Thousands place
    538 % 1000 = 538
    1000 - 538 == 462
    1000 / 2 == 500
    
    462 < 500 so
      538 + 462 == 1000
    Is that what you're looking for? If so, I don't imagine you would have trouble turning those examples into a general algorithm. I wrote a two line function that performs the requisite operations.
    My best code is written with the delete key.

  11. #11
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Somehow, I feel like this entire post was the ultimate manipulation to get someone to do his homework for him.
    Sent from my iPadŽ

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I feel like this entire post was the ultimate manipulation to get someone to do his homework for him.
    Probably, but he still has to verify the solutions suggested and write the code.
    My best code is written with the delete key.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I feel like this entire post was the ultimate manipulation to get someone to do his homework for him.
    There was no real danger of that because the specification was so horribly broken as to make any serious attempt meaningless.
    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.

  14. #14
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well for starters, you should go read the forum guidelines link at the top of the forum. In an effort to not be too abusive, I'll assume you missed it, and that you didn't actually ignore it.
    If you don't start getting meaner and more abusive I'm gonna report you.

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >If you don't start getting meaner and more abusive I'm gonna report you.
    We should temporarily ban quzah so that he can reflect on his poor attitude.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed