Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ // Program AddSub reads in a letter (A or S) and two int values. // If the letter is A, the two values are
C++
// Program AddSub reads in a letter (A or S) and two int values.
// If the letter is A, the two values are added.
// If the letter is S, the second is subtracted from the first.
// The answer is printed appropriately labeled.
#include
using namespace std;
int main ()
{
char operatorCode;
int value1;
int value2;
int answer;
cout
cout
cout
cin >> operatorCode;
cin >> value1 >> value2;
if (operatorCode = 'A')
{
answer = value1 + value2;
cout
}
else
answer = value1 - value2;
cout
Exercise 1: Program AddSub is supposed to read in a letter and two integer values and print elther the sum of the two values or the difference of the two values depending on the letter read. It is such a simple program, but it doesn't even compile! Correct the program and describe the errors. Exercise 2: Now that the program compiles, run it with the following sets of values. Input Values A 10 20 A 20 10 S 10 20 s 20 10 Means What Is Printed Add 10 to 20 Add 20 to 10 Subtract 20 from 10 Subtract 10 from 20 Exercise 3: Unless you corrected the logic errors in Exercise 1, your answers are incorrect. Locate the logic errors and rerun your program until you get the correct answers. Describe the errors return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started