I finaly got it to work. I know it's messy and completely drawn out, but the only way I seemed to understand how to do this, is when I had a problem, I created more code to fix the problem rather than just fix what I have, = 0
hence the spagetti. It still has issues with prime numbers though, such as 7/11 etc, but I got it to work where if the numerator is larger than the denom, such as 11/7, it now works fine.
Code:
#include <stdio.h>
int main (void)
{
int a, b, temp=0,m=0;
int gcd(int,int);
int lcm(int,int);
int whole, minus, top, bottom, top2, bottom2, newnom;
printf ("Enter fraction: ");
scanf ("%d/%d",&a,&b);
whole = a / b;
minus = a - (whole*b);
top = lcm(a,b) / b;
bottom = lcm(a,b) / gcd(a,b);
if ((a-b<=0))
{
temp=a;
a=b;
b=temp;
}
if(whole == 0)
printf("result: %d/%d\n", top, bottom);
while(whole != 0){
if(a % b == 0)
printf("result: %d\n", whole);
break;
}
if( a % b > 0 && a <= 9)
printf("result: %d + %d/%d\n", whole, minus, b);
newnom = a % b;
top2 = newnom / gcd(a,b);
bottom2 = bottom / top;
if( a % b > 0 && a > 9)
printf("result: %d + %d/%d\n", whole, top2, bottom2);
printf("PROGRAM ENDS\n");
return 0;
}
int gcd(a,b)
{
int t,r;
r=a%b;
if (r==0)
return b;
else
return gcd(b,r);
}
int lcm(a,b)
{
int m,n;
m=a*b;
n=m/gcd(a,b);
return n;
}
[/CODE]
P.S. I took out the part where if the user entered zero, the program would ask them to enter a nonzero number, because it wasn't necessary and the compiler website my prof. used to grade the program didn't require it.