Create a simple calculator that will add subtract multiply C

Create a simple calculator that will add, subtract, multiply. Create a function that will preform each of the operations. for add use the prototype void add(void) for subtraction use the prototype int subtract(x,y) for multiplication use the prototype int multi(void)

Solution

// C++ calculator that will add, subtract, multiply

#include <cstdlib>
#include <iostream>
#include <stdlib.h>   
#include <string.h>
#include <algorithm>
#include <fstream>

using namespace std;

int multi(int x,int y)
{
return x*y;
}
void add(int x, int y)
{
cout << x << \"+\" << y << \" : \" << (x+y) << endl;
}

int subtract(int x, int y)
{
return x-y;
}

int main()
{
char op;
int number1,number2;
cout << \"Enter operator either + or - or * : \";
cin >> op;

cout << \"Enter two operands: \";
cin >> number1 >> number2;

switch(op)
{
case \'+\':
add(number1,number2);
break;
case \'-\':
cout << number1 << \"-\" << number2 << \" : \" << subtract(number1,number2) << endl;
break;
case \'*\':
cout << number1 << \"*\" << number2 << \" : \" << multi(number1,number2) << endl;
break;
default:
cout << \"Invalid Input\ \";
break;
}
return 0;
}

/*
output:

Enter operator either + or - or * : *
Enter two operands: 3 4
3*4 : 12


Enter operator either + or - or * : -
Enter two operands: 3 4
3-4 : -1


Enter operator either + or - or * : +
Enter two operands: 3 4
3+4 : 7


*/

Create a simple calculator that will add, subtract, multiply. Create a function that will preform each of the operations. for add use the prototype void add(voi
Create a simple calculator that will add, subtract, multiply. Create a function that will preform each of the operations. for add use the prototype void add(voi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site