Hi all. im kinda new to c and I could use some help to point me in the right direction. basically I have to perform basic math between fractions and put out a result in fraction form.
right now i am just trying to get the add and multiply functions to work . this is what i have so far..
any help is appreciated ...
right now i am just trying to get the add and multiply functions to work . this is what i have so far..
Code:
#include <cstdlib> #include <iostream> #include <math.h> char symbol; int num1=0; int num2=0; int denum1=0; int denum2=0; int ansnum=0; int denumans=0; long ans=0; int add(int n1,int d1,int n2,int d2) { int hold1 = 0; int hold2 = 0; char symhold = '/'; hold1=((n1 * d2) + (n2 * d1)); hold2=(d1 * d2); printf ("%d / %d\n"),hold1,hold2; return (hold1); return (hold2); } int mult(int n1,int d1,int n2,int d2) { int hold1 = 0; int hold2 = 0; char symhold = '/'; hold1=(n1 * n2); hold2=(d1 * d2); printf ("%d / %d\n"),hold1,hold2; return (hold1); return (hold2); } int main(void) { char ra = 'y'; while (ra != 'n') { printf(" Eter the symbol "); scanf ("%c",&symbol); printf("Enter The 1st Numerator "); scanf("%d",&num1); printf("Enter the 1st Denomanator "); scanf("%d",&denum1); printf("Enter the 2nd Numerator "); scanf("%d",&num2); printf("Enter the 2nd Denomanator "); scanf("%d",&denum2); if (symbol = '+') { ans= add(num1,denum1,num2,denum2); // printf(" %d\n",ans); } if (symbol = '*') { ans= mult(num1,denum1,num2,denum2); // printf(" %d\n",ans); } getchar(); printf("would you like to use the fraction operator again? Y or N\n"); ra = getchar(); getchar(); } }
Comment