How to prevent alpha from keying in ??

void DecToHex()
{

while (true)
{
int InputNum;
system("cls");
printf("\n");
printf("\n\tDecimal to Hexadecimal Conversation");
printf("\n\t====================================");
printf("\n\tPlease enter Decimal Value< 1 - 999999 >: "); //User to key in a decimal value betwewnt 1 to 999999 before it can do the function
scanf("%d",&InputNum);

if (InputNum>=1&&InputNum<=999999)
{
int Result = InputNum;
int Remainder[7] , Divider = 16 , i ; // Remainder only allowed to key in 6 numbers .
printf("\n");
printf("\n");

for (int i = 0; i < 8; i++) // loop 8 times for the dividing the value at the same time changing its value for each loop .
{
Remainder[i] = Result % Divider;
printf("\n\t16 > %-6d - %d" , Result , Remainder[i] );
Result /= Divider;
printf("\n\t -------");
_sleep(500);

}

printf("\n\t %d",Result); // last result to be shown after 8loops ().
_sleep(500);
printf("\n");
printf("\n");
printf("\tThe Hexadecimal eqivalent of decimal %d = " , InputNum); // The final sentence showing result

for (int i=7;i>=0;i--) //This is to print out the Remainder in another direction therefore is decreasing loop .
{
printf("%X ",Remainder[i]); // Converting the Remainder to Hexadecimal to be printed out at the final sentence
_sleep(100);
}
getch();
break;
}
else
{
printf("\n");
printf("\tPlease enter Decimal Value between <1 to 999999>");
_sleep(1000);
}
}
}
Topic archived. No new replies allowed.