I have this program to write that will add two fractions input by the user. I need to do this using pointers to structs. I have the code written, but it will not run all the way through. Could someone help me debug this thing and get it running properly.
#include <stdio.h>
typedef struct
{
int numerator;
int denominator;
}FRACTION;
void Add(FRACTION *pfrac1, FRACTION *pfrac2);
void Display(FRACTION *pres);
int main()
{
FRACTION fr1;
FRACTION fr2;
FRACTION result;
FRACTION *pfrac1;
FRACTION *pfrac2;
FRACTION *pres;
pfrac1 = &fr1;
pfrac2 = &fr2;
pres = &result;
printf("Please enter the first fraction in the form x/y: ");
scanf("%d /%d", pfrac1->numerator, pfrac2->denominator);
printf("Please enter the second fraction in the form x/y: ");
scanf("%d /%d", pfrac2->numerator, pfrac2->denominator);
Add(&fr1, &fr2);
Display(&result);
getchar();
getchar();
}
void Add(FRACTION *pfrac1, FRACTION *pfrac2)
{
FRACTION result;
FRACTION *pres;
pres = &result;
pres->numerator = (pfrac1->numerator * pfrac2->denominator) + (pfrac2->numerator * pfrac1->denominator);
pres->denominator = (pfrac1->denominator * pfrac2->denominator);
}
void Display(FRACTION *pres)
{
printf("\nThe result is %d/%d", pres->numerator, pres->denominator);
}