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; 
}
Re: Double Check, Using Switch to create function 80 80

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

Re: Double Check, Using Switch to create function 80 80

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 . . .
Re: Double Check, Using Switch to create function 80 80

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.

Re: Double Check, Using Switch to create function 80 80

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 . . .
Re: Double Check, Using Switch to create function 80 80
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 . . .
Re: Double Check, Using Switch to create function 80 80

I think I got it nevermind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.