The code is atleast I believe it is reading in the intergers I put in, however the operator functions are not working the way I need them to. When I enter numbers it always gives me whatever numbers I used for numerators over 0. So not sure if it's something with my logic or it happens to be a coding error.
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int a;
int b;
int c;
int d;
int e;
int f;
float x;
float y;
char oper;
printf("Enter the first fraction as two intergers separated by a slash:");
scanf("%d/%d",&a,&b);
printf("Enter the second fraction as two integers separated by a slash:");
scanf("%d/%d",&c,&d);
printf("Enter the third fraction as two intergers separated by a slash:");
scanf("%d/%d",&e,&f);
printf("Enter an arithmetic operator( +,* ):");
scanf("%s",&oper);
switch(oper)
{
case '*':
{
x = (a)*(c)*(e);
y = (b)*(d)*(f);
printf("%d/%d\n",x,y);
};
break;
case '+':
{
x = ((a)*(d)*(f))+((c)*(b)*(f))+((e)*(b)*(d));
y = (b)*(d)*(f);
printf("%d/%d\n",x,y);
};
break;
}
getch();
return 0;
}
This post has been edited by heckyaaa: 07 October 2009 - 09:16 AM

New Topic/Question
Reply




MultiQuote




|