Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting a value from a few numbers

    hi ppl,

    i have a problem with my program where i just need to get the 1st number from a series of the values. Eg : 125 - i need to get the value 5 from the value. do C language has the code in getting the value?

    thanks in advance
    arch

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by arch
    do C language has the code in getting the value?
    Yes it does.

    Now you'll probably ask "what are these codes?". But to answer that we need to know more about the problem. How is this "series of the values" stored in the program? Is it an array? A string? A bunch of int variables?

    shmoove

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it's a bunch of int variables which is to be display as a char value. So the output of the program code will be something like :

    cout << x << "." << y << z ;

    which mean if my result is 128/51 = 2.509, i would like to get the number 2
    and if the result is 128/5.1 = 25.09 i like to get the number 5
    and 250.0, number to get will be 0.
    which i dun tink char variable can be displayed numbers with decimal point.

    The final result will display as 2.50.

    cheers,
    arch

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well you can use arithmethic operations to achieve this:
    If you multiply or divide by 10 you can move the digits around, and the % (modulo) operator gives you the remainder from an integer division so x % 10 will give you the right digit from x.
    But if this is all in order to display results on screen then I think you should check this recent thread.

    shmoove

  • #5
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks shmoove.

    great help from you.


    arch

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    The floor() function may be of some use in this instance as well.
    OracleGuy

  • #7
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi sorry for the trouble again.

    i manage to come out with the display using the %10.
    But would like to check if the " % " can be use to transfer the value from the C programming to the PIC chip?

    thanks
    Arch


  •  

    Posting Permissions

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