#include <stdio.h>
void
scan_fraction(int *nump, int *denomp)
{
char slash;
int status;
int error;
char discard;
do {
// no errors detected yet
error = 0;
// get a fraction from the user
printf("Enter a common fraction as two integers separated ");
printf("by a slash > ");
status = scanf("%d %c %d",nump, &slash, denomp);
// validate the fraction
if (status < 3)
{
error = 1;
printf("Invalid. Please read directions carefully\n");
}
else
if (slash != '/')
{
error = 1;
printf("Invalid fraction (no slash)");
}
else
if (*denomp <= 0)
{
error = 1;
printf("Invalid. Denominator must be positive\n");
}
// discard extra input characters
do {
scanf("%c", &discard);
} while (discard != '\n');
} while (error);
}
int main()
{
int numerator, denominator;
double real_number;
scan_fraction (&numerator, &denominator);
real_number = (double)numerator / denominator;
printf ("%lf", real_number);
return (0);
}