Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************************
- *******************************************************************************************
- ** Write a program that takes an operation followed by two operands and outputs the result. For
- ** example:
- ** + 100 3.14
- ** * 4 5
- **
- */
- #include "../../std_lib_facilities.h"
- int main()
- {
- cout << "Pass an operator followed by its operands and execute the expression ( (+ 1 1) => 2 ):\n";
- char ops = ' ';
- int n1 = 0, n2 = 0;
- double res;
- cin >> ops;
- cin >> n1 >> n2;
- cout << "The result of (" << ops << " " << n1 << " " << n2 << ") is: \n";
- if (ops == '+') {
- res = n1 + n2;
- } else if (ops == '-') {
- res = n1 - n2;
- } else if (ops == '*') {
- res = n1 * n2;
- } else if (ops == '/') {
- res = n1 * n2;
- } else if (ops == '%') {
- res = n1 % n2;
- }
- cout << res << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement