Can someone show me how to change the cases down below to call functions for add, subtract, divide, multiply.
Also return the answer back to the case
to display the result in the case.
Prototype the functions before main
and add the function definitions
after main.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int first;
int second;
char op;
cout << "Enter the first number: ";
cin >> first;
cout << endl;
cout << "Enter the operator: + or - or * or / : ";
cin >> op;
cout << endl;
cout << "Enter the second number: ";
cin >> second;
cout << endl;
if (second == 0)
cout << "ERROR: cannot divide by zero" << endl;
else
switch (op)
{
case '+':
cout << first << " " << op << " " << second << " = " << first + second << endl;
break;
case '-':
cout << first << " " << op << " " << second << " = " << first - second << endl;
break;
case '*':
cout << first << " " << op << " " << second << " = " << first * second << endl;
break;
case '/':
cout << first << " " << op << " " << second << " = " << first / second << endl;
break;
default:
cout << first << " " << op << " " << second << " = " << "Illegal operation" << endl;
break;
}
return 0;
}