#include <stdio.h>
#include "gm.h"
void	SmartScan(char *,DEC *);
void main(void);

void	main()
{
	DECP	x;

	SmartScan("Type a number:  ", x);
	PrintDecimal("You typed a %t\n", x);
}

void	SmartScan(s, pd)
char	*s;
DEC	*pd;
{
	short	done;
	int	i;
	
	if (!pd)  {
		printf("Error:  null DEC pointer\n");
		return;
	}
	
	ClearMathError();
	done=FALSE;
	while (!done)  {
		printf("%s",s);
		ScanDecimal("%t",pd);
		i = ReturnMathErrAndClear();
		if (i==GM_SUCCESS)
			done=TRUE;
		if (i==GM_CNVRW)  {
			done=TRUE;
			printf("Warning:  Digit loss due to rounding\n");
		}
		if (i==GM_CNVRE)
			printf("Error:  Number out of range\n");
		if (i==GM_NAN)
			printf("Error:  Not a number\n");
	}
	return;
}