# Thread: This seemed impossible!Can anyone help??

1. ## 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!!!!

2. 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.

3. > i WILL use scanf() right?
Sure, to read the number in.

The rest is up to you and your skill at mathematics.

4. 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.

5. LOL @ quzah... my, u sure are scary..

6. 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;
}

7. >Please tell me what's wrong in this code
Please tell us what you're expecting as the output.

8. > the output must be: Round of at Tens Value is: 1
How did you get 1 ?
I would expect 4 or 5, but 1 ?

9. 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???

10. 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.

11. Somehow, I feel like this entire post was the ultimate manipulation to get someone to do his homework for him.

12. >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.

13. > 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.

14. 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. >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.

Popular pages Recent additions