Not sure why it's not letting me choose the operation I want where I put "Enter an operation symbol..", I'm supposed to use switch statements to compute functions.

#include <iostream> 
#include<cmath>
#include <iomanip> 
#include <string>

using namespace std;

int main()
{
    int type;
    int a, b, c, d;
    char op;

    cout << fixed << showpoint << setprecision(2); 

    //select operation
    cout << "Enter a fraction: "; 
    cin >> a; cin.ignore(); cin >> b;
    cout << "Enter another fraction: ";
    cin >> c; cin.ignore(); cin >> d; 
    cout << "\tEnter an operation symbol (+,-, *, /): "; 
    cin >> op; cin.ignore();

    //operate function
    switch(op)
    {
    case '+' : cout << a << "/" << b << "+" << c << "/" << d << "=" << (a*d)+(c*b) << "/" << (d*b) << endl;
    break;
    case '-' : cout << a << "/" << b << "+" << c << "/" << d << "=" << (a*d)-(c*b) << "/" << (d*b) << endl;
    break;
    case '*' : cout << a << "/" << b << "+" << c << "/" << d << "=" << (a*c) << "/" << (d*b) << endl; 
    break;
    case '/' : cout << a << "/" << b << "+" << c << "/" << d << "=" << (a*d) << "/" << (c*b) << endl; 
    break;
    }


    //end program
    system ("pause");
    return 0; 
}

In what way does it "not let you"? Does the keyboard refuse to accept any entry when you get to the operator selection?

It comes out like this but when it asks for you to enter an operation symbol, it just automatically does it without letting me choose which one I want.

Enter a fraction: 12/5
Enter another fraction: 2.1/7.5
        Enter an operation symbol (+,-, *, /): 12/5+2/1=12/10
Press any key to continue . . .

When it asks you to enter a fraction, you're supposed to just type number <enter> number<enter>. Not the / sign.

Enter a fraction: 2
3
Enter another fraction: 4
5
    Enter an operation symbol (+,-, *, /): +
2/3+4/5=22/15

You're typing strings made of number/number when it's expecting a single int value.

Edited 1 Year Ago by Moschops

Ok, so if I want to make the output look like this: How would I make it work?

Enter a fraction: 12/5
Enter another fraction: 2.1/7.5
        Enter an operation symbol (+,-, *, /): *
            (12.00/5.00)+(2.10/7.50) = 2.52/37.5
Press any key to continue . . .
Enter a fraction: 12
5
Enter another fraction: 2.1
7.5
   Enter an operation symbol (+,-, *, /): *
        (12.00/5.00)+(2.10/7.50)=25.20/37.50
Press any key to continue . . .

I want it to look like this though:

Enter a fraction: 12/5
Enter another fraction: 2.1/7.5
        Enter an operation symbol (+,-, *, /): *
            (12.00/5.00)+(2.10/7.50) = 2.52/37.5
Press any key to continue . . .
This article has been dead for over six months. Start a new discussion instead.