//******************************
//* Programmed by: psybuck2002us *
//* Date: April 20, 2005. *
//* Title: Round To Nearest Quarter *
//* Compiler: Borland C++ COmpiler 5.02 *
//******************************
#include <stdio.h>
#include <math.h>
#include <conio.h>
int main(void)
{
float input, down, rnum;
printf("Enter Value: ");
scanf("%f", &input);
down = floor(input);
if(input > down && input < (down + 0.25))
{
(input < (down + (0.25 / 2))) ? rnum = down : rnum = down + 0.25;
}
if(input > (down + 0.25) && input < (down + 0.50))
{
(input < ((down + 0.25) + (0.25 / 2))) ? rnum = down + 0.25 : rnum = down + 0.50;
}
if(input > (down + 0.50) && input < (down + 0.75))
{
(input < ((down + 0.50) + (0.25 / 2))) ? rnum = down + 0.50 : rnum = down + 0.75;
}
if(input > (down + 0.75) && input < (down + 1))
{
(input < ((down + 0.75) + (0.25 / 2))) ? rnum = down + 0.75 : rnum = down + 1;
}
printf("\n\n\nThe Nearest Quarter Rounded Value is: %.2f", rnum);
getch();
return 0;
}