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
02-23-2005, 02:19 PM
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?
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.
02-24-2005, 09:51 AM
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 (http://www.codingforums.com/showthread.php?t=52914).
great help from you.
02-27-2005, 01:49 AM
The floor() function may be of some use in this instance as well.
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?