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.
1
Expert's answer
2013-02-19T09:20:30-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS