Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
