|
-
February 6th, 2005, 08:36 PM
#1
2 averaged Floats printf'ed as a decimal
Greetings:
I am putting the final touches on an assignment, but I am not happy with one section, which, although it may fufill the requirement in some fashion, is not exact. The overall program (in C) is to input 10 characters, run a bubble-sort and first; display sort as unsorted, then sorted (lowest to highest), then the smallest, midpoint, and finally largest char in sort. I have written all the full code and it runs beautifully, but when it outputs a value for the midpoint char display (actually, the 5th and 6th chars added and then divided by two) the resulting number is not correct. Example: the equation should render (( 4 +5=9\ 2))= 4.5 but in my code, the answer would be "4".
Included is the snippet of code concerning this error; I have searched forums, tried using float, int, "%2d" , "%.2f", and with no valid change. I am missing something.
Thank-you in advance,
~Mansoor
Code:
{
M=((e+f)/2);
printf("\n The middle value of your sorted list is { %.2c}\n",M);
}
"Nay, you love this present life!"
Save your keystrokes!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|