switch and fractions

hi guys, i need help adding subtracting multiplying and dividing fractions that the user enters into a code. here is what i have so far, but when i run it, the numbers come out to 0 plus 0 = 0. i havent started on the other mathematical operations yet. any ideas how to make this work? i am supposed to use a switch structure to process the menue choices but idk what thatis. heere is my code:

#include <iostream>
using namespace std;
#include <cmath>

int main()
{
int num;
int den;
int x;
int y;
char slash;

cout << "Enter fraction x: ";
cin >> num >> slash >> den;
'\n';
cout << "Enter fraction y: ";
cin >> x >> slash >> y;
cout << endl;
cout << endl;
cout << "Please choose one:" << endl;
cout << "(1) Add fractions (x + y)" << endl;
cout << "(2) Subtract fractions (x - y)" << endl;
cout << "(3) Multiply fractions (x * y)" << endl;
cout << "(4) Divide fractions (x / y)" << endl;
cout << "(5) Quit program" << endl;
cout << endl;
cout << endl;

int choice;

cout << "Your choice: ";
cin >> choice;
while ( choice < 1 || choice > 5)
{
cout << "Invalid entry. Please re-enter: ";
cin >> choice;
}
if (choice = 1)
{
double first = num/den;
double second = x/y;
cout << first << " plus " << second << " = " << first + second;
}
return 0;
}
Make the input two pairs of integers, each pair separated by a '/'.
Call them a,b,c and d.
Now use grade-school math:
a/b+c/d=(ad+cb)/bd
a/b-c/d=(ad-cb)/bd
(a/b)*(c/d)=(ac)/(bd)
(a/b)/(c/d)=(ad)/(bc)
if you want to operate on a number of fractions in a continuous manner use a loop and obtain the Lowest Common Multiple of the denominators as each new fraction is entered.
Topic archived. No new replies allowed.