How do i make the program to print Sorry... if user enter a 4 decimal place number???
Code:
# include <stdio.h>
main()
{
float length;
float cm;
float m;
float km;
float inch;
float yard;
float mile;
printf("Metric-Imperial Conversion\n\n"); /* This is the program name */
printf("This program allows values up to 3 decimal place\n");
printf("Get Length: "); /*user input values to be convertered*/
scanf("%f" , &length);
if ( length < 0 ) /*How do i make the program to print Sorry... if user enter a 4 decimal place number???*/
{
printf("\aSorry, Pls re-enter value \n");
}
else {
cm = length * 2.5400;
m = length * 0.91440;
km = length * 1.60934;
printf("\n\nFrom %.3f Inch to CM: %.3f \n", length, cm);
printf("From %.3f Yard to Metres: %.3f \n", length, m);
printf("From %.3f Miles to KM: %.3f \n\n\n", length, km);
inch = length * 0.393700;
yard = length * 1.093613;
mile = length * 0.621371;
printf("From %.3f CM to Inch: %.3f \n",length, inch);
printf("From %.3f Meters to Yard: %.3f \n",length, yard);
printf("From %.3f KM to Mile: %.3f \n\n", length, mile);
printf("Have a Good Day!!\n");
}
}