67 095
Assignments Done
99,3%
Successfully Done
In November 2018

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.
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions