# Answer to Question #24529 in C++ for monami

Question #24529

Create a C++ program that performs 4 mathematical operations such as addition, subtraction, multiplication and division.

The numbers to be entered must have 1 whole number and with 2 decimal points.

The output must be in the center of the screen.

The numbers to be entered must have 1 whole number and with 2 decimal points.

The output must be in the center of the screen.

Expert's answer

#include <conio.h>

#include <iomanip>

#include <iostream>

using namespace std;

int main()

{

double a, b;

char sign;

double result;

cout << "Enter an expression: ";

cin >> setprecision(2) >> a >> sign >> setprecision(2) >> b;

switch (sign)

{

case '+':

result = a + b;

break;

case '*':

result = a * b;

break;

case '-':

result = a - b;

break;

case '/':

result = a / b;

break;

default:

cout << "Invalid input." << endl;

_getch();

return -1;

}

cout << setw(40) << result << endl;

_getch();

return 0;

}

#include <iomanip>

#include <iostream>

using namespace std;

int main()

{

double a, b;

char sign;

double result;

cout << "Enter an expression: ";

cin >> setprecision(2) >> a >> sign >> setprecision(2) >> b;

switch (sign)

{

case '+':

result = a + b;

break;

case '*':

result = a * b;

break;

case '-':

result = a - b;

break;

case '/':

result = a / b;

break;

default:

cout << "Invalid input." << endl;

_getch();

return -1;

}

cout << setw(40) << result << endl;

_getch();

return 0;

}

## Comments

## Leave a comment