Fix any errors that you find. Use in-line comments to explain how and why you fixed the bugs. Test your program. If you found and fixed all the errors, your code should function as specified: The code should allow users to enter basic, one operator arithmetic expressions using integers or doubles. Then, it should calculate the result of the expression and output the results. For example, if the user inputs “2 + 2,” the calculator should output “2 + 2 = 4.” The operations the program should perform are addition (+), subtraction (-), multiplication (*), and division (/). The user should be asked whether they wish to continue after evaluating each expression. If the user types “Y” or “y,” the program should ask for a new arithmetic expression. If the user types “N” or “n,” the program should terminate with the message: “Program Finished.”

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Fix any errors that you find. Use in-line comments to explain how and why you fixed the bugs.
  1. Test your program. If you found and fixed all the errors, your code should function as specified:
    1. The code should allow users to enter basic, one operator arithmetic expressions using integers or doubles. Then, it should calculate the result of the expression and output the results. For example, if the user inputs “2 + 2,” the calculator should output “2 + 2 = 4.”
    2. The operations the program should perform are addition (+), subtraction (-), multiplication (*), and division (/).
    3. The user should be asked whether they wish to continue after evaluating each expression. If the user types “Y” or “y,” the program should ask for a new arithmetic expression. If the user types “N” or “n,” the program should terminate with the message: “Program Finished.”
```cpp
#include <iostream>
c/Calculator.cpp
void main()
{
    char statement[100];
    int op1;
    int op2;
    char operation;
    char answer = "Y";
    while (answer=='y')
    {
        cout << "Enter expression" << endl; // Space needed after <<
        cin >> opl >> operation >> op2; //Swap the op1 and op2, wrong place.
        if (operation == '+') // Change " " to ' ' for character
            cout << opl << " + " << op2 << " = " << opl + op2 << endl; //Reverse the >> after op2
        if (operation == '-')
            cout << opl << " - " << op2 << " = " << opl - op2 << endl; //Reverse the >> for cout statement 
        if (operation == '*') //Semicolon needed
            cout << opl << " * " << op2 << " = " << opl * op2 << endl; //Add ; to end of line and replaced the / for *
        if (operation == '/') //Semicolon needed
            cout << opl << " / " << op2 << " = " << opl / op2 << endl; //Replace * for /
        
        cout << "Do you wish to evaluate another expression? " << endl;
        cin >> answer;
    }
}
```

### Explanation

The above C++ code is intended to be a simple calculator program. It allows the user to input an arithmetic expression, evaluates it, and then outputs the result. Below are the key elements and annotations for the code:

1. **Libraries and Main Function**: 
   - `#include <iostream>`: This includes the I/O stream library for input and output functions.
   - `void main()`: The program execution starts from this main function.

2. **Variables**:
   - `char statement[100];`: An array to hold the expression as a string.
   - `int op1, op2;`: Integer variables to hold the two operands.
   - `char operation;`: Character variable to store the operator.
   - `char answer = "Y";`: Character variable to control the loop, initialized with "Y".

3. **Input and Calculation Loop**:
   - The program uses a `while` loop to repeatedly ask for input as long as the user decides to continue (answer is '
Transcribed Image Text:```cpp #include <iostream> c/Calculator.cpp void main() { char statement[100]; int op1; int op2; char operation; char answer = "Y"; while (answer=='y') { cout << "Enter expression" << endl; // Space needed after << cin >> opl >> operation >> op2; //Swap the op1 and op2, wrong place. if (operation == '+') // Change " " to ' ' for character cout << opl << " + " << op2 << " = " << opl + op2 << endl; //Reverse the >> after op2 if (operation == '-') cout << opl << " - " << op2 << " = " << opl - op2 << endl; //Reverse the >> for cout statement if (operation == '*') //Semicolon needed cout << opl << " * " << op2 << " = " << opl * op2 << endl; //Add ; to end of line and replaced the / for * if (operation == '/') //Semicolon needed cout << opl << " / " << op2 << " = " << opl / op2 << endl; //Replace * for / cout << "Do you wish to evaluate another expression? " << endl; cin >> answer; } } ``` ### Explanation The above C++ code is intended to be a simple calculator program. It allows the user to input an arithmetic expression, evaluates it, and then outputs the result. Below are the key elements and annotations for the code: 1. **Libraries and Main Function**: - `#include <iostream>`: This includes the I/O stream library for input and output functions. - `void main()`: The program execution starts from this main function. 2. **Variables**: - `char statement[100];`: An array to hold the expression as a string. - `int op1, op2;`: Integer variables to hold the two operands. - `char operation;`: Character variable to store the operator. - `char answer = "Y";`: Character variable to control the loop, initialized with "Y". 3. **Input and Calculation Loop**: - The program uses a `while` loop to repeatedly ask for input as long as the user decides to continue (answer is '
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education