2

Simple C++ calculator

/*
A simple calculator to add, subtract, multiply or divide any two numbers.
*/

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    double x; //This is the first number

    double y; //This is the second number

    char operation; //Define the mathematical operation

    double result; //Output result

    string tty; //Showing operator in use.

    cout << "Enter first number: ";
    cin >> x;

    cout << "Enter second number: ";
    cin >> y;

    cout << "Enter a to add, s to subtract, m to multiply and d to divide.: ";
    cin >> operation;

    if( operation == 'a'){
        result = x + y;
        tty = "+";
    }
    else if( operation == 's' ){
        result = x - y;
        tty = "-";
    }
    else if( operation == 'm' ){
        result = x * y;
        tty = "*";
    }
    else if( operation == 'd' ){
        result = x / y;
        tty = "/";
    }
    else{
        cout << "Enter a valid operation";
    }

    cout << x << tty << y << "= " << result << endl;
    return 0;
}