I was looking for some source code to learn a bit more about C, found a fractions calculator and decided I'd have a go at making one myself in the same style, without copying
Got it to the stage where it'll work out the fractions being entered... compiled it... went to sleep.
Woke up, recompiled it to the same point (because I'm paranoid, see earlier thread in Back Porch ) and went to run it... only to get it playing infinite loop on me...
Here's the source, the gremlins that be decided it was going to bugger up around second fraction/switch loop time There is more, but it doesn't ever get there.... lol
#include <stdio.h>
#define QUIT 'q'
int nom1 = 0, nom2 = 0, denom1 = 0, denom2 = 0;
int add(), subtract(), multiply(), divide();
int nom1, nom2, denom1, denom2;
main(void)
{
int choice = 0;
char quit = 0;
printf("Enter each fraction in the form numerator/denominator\n");
printf("Enter the first fraction\n");
scanf("%d\%d", &nom1, &denom1);
printf("Enter the second fraction\n");
scanf("%d\%d", &nom2, &denom2);
do
{
printf("\nKey:\n");
printf("1\t Add\n");
printf("2\t Subtract\n");
printf("3\t Multiply\n");
printf("4\t Divide\n");
printf("Enter an operation\n");
scanf("%d", &choice);
switch (choice)
{
case(1):
Add();
break;
case(2):
Subtract();
break;
case(3):
Multiply();
break;
case(4):
Divide();
break;
case(0):
printf("Enter a valid choice");
break;
default:
printf("Enter a valid choice");
break;
}
} while(choice < 1 || choice > 4);
while(quit != QUIT);
{
printf("\n\nEnter q to quit\n");
scanf("%c", &quit);
}
}
I know that it's just something REALLY stupid
But I can't see it, it's staring me right it the face I know it, I must have changed something I think... but I can't for the life of me see it...
Oh, and trying to stare the code out doesn't work either ,
IntelMole[/quote]