Write a C++ program called hw.cpp that performs addition and multiplication operations. The user enters an initial number and then continues to add or multiply new user-specified numbers to the growing sum/product. At each loop repetition, the user enters x to multiply, + to add, or q for quit. If s/he chooses add or multiply, the user then specifies the additional number to be added or multiplied. The program reports the latest sum/product. Note:    operator is a C++ reserved name (keyword). Do not use it as a variable name.   Test Case Output Welcome to the math loop. Give a first number: 5 Choose an operation: + Choose a number to add: 6 5+6 = 11 Choose an operation: x Choose a number to multiply: 3 11x3 = 33 Choose an operation: x Choose a number to multiply: 2 33x2 = 66 Choose an operation: + Choose a number to add: 15 66+15 = 81 Choose an operation: q We are finished!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.2: The If-else Statement
Problem 3E
icon
Related questions
icon
Concept explainers
Question

Write a C++ program called hw.cpp that performs addition and multiplication operations.

The user enters an initial number and then continues to add or multiply new user-specified numbers to the growing sum/product.

At each loop repetition, the user enters x to multiply, + to add, or q for quit. If s/he chooses add or multiply, the user then specifies the additional number to be added or multiplied. The program reports the latest sum/product.

Note:    operator is a C++ reserved name (keyword). Do not use it as a variable name.

 

Test Case Output

Welcome to the math loop.

Give a first number: 5

Choose an operation: +

Choose a number to add: 6

5+6 = 11

Choose an operation: x

Choose a number to multiply: 3

11x3 = 33

Choose an operation: x

Choose a number to multiply: 2

33x2 = 66

Choose an operation: +

Choose a number to add: 15

66+15 = 81

Choose an operation: q

We are finished!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operators
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning