Can someone tell me how I can let the user input a certain operator into this calculator function please?
I would like to use cin to input the operator if possible because it is one of the only input commands I know. I'm sorry for being such a noob, I just started c++ 3 days ago.
// Calculator.cpp : Defines the entry point for the console application.
// Calculates the value of two numbers based on the four main operations.
#include "stdafx.h"
#include <iostream>
int add (int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int y);
int main()
{
usingnamespace std;
int x;
int y;
cout << "Calculator v1"<< endl;
cout << "Please Enter A Number"<< endl;
cin >> x;
cout << "Please Enter A Second Number"<< endl;
cin >> y;
cout << "What Operation Do You Wish To Perform?"<< endl;
cout << "Choose From +, -, *, And /"<< endl;
return 0;
}
int add(int x, int y)
{
return x + y;
}
int subtract(int x, int y)
{
return x - y;
}
int multiply(int x, int y)
{
return x * y;
}
int divide(int x, int y)
{
return x / y;
}
cout << "What Operation Do You Wish To Perform?"<< endl;
cout << "Choose From +, -, *, And /"<< endl;
char operation = '+' ;
cin >> operation ;
int result = 0 ;
switch(operation)
{
case'+': result = add(x,y) ; break ;
// etc.