c++ fractions
Nov 3, 2013 at 10:46pm UTC
Im writing a c++ program that uses fractions and im having trouble figuring out how i allow people to enter fractions into the program. I have it to were im asking people to enter the fraction but it doesn't allow me to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
double fraction_a1,
fraction_a2,
fraction_s1,
fraction_s2,
fraction_m1,
fraction_m2,
fraction_d1,
fraction_d2;
const int ADD_FRACTION = 1,
SUBTRACT_FRACTION = 2,
MULTIPLY_FRACTION = 3,
DIVIDE_FRACTION = 4,
Quit_Program = 5;
cout << "\t\tFraction Calculator\n\n"
<< "1. Add Fractions\n"
<< "2. Subtract Fractions\n"
<< "3. Multiply Fraction\n"
<< "4. Divide Fraction\n"
<< "5. Quit Program\n\n"
<< "Enter Your choice: " ;
cin >> choice;
if (choice == ADD_FRACTION)
{
cout <<" Enter First Fraction" <<endl;
cin >> fraction_a1;
cout <<"Enter Second Fraction" <<endl;
cin >> fraction_a2;
}
return 0;
}
Thank you in advance
Nov 3, 2013 at 11:08pm UTC
Ask the user for a numerator and a denominator, do your math magic, then format your answer however you want your output to look like.
Topic archived. No new replies allowed.