Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

modify and extend the program #include using namespace std; #include using namespace std; int main() { float num=0; float total=0; char symbol; cout < <

modify and extend the program

#include

using namespace std;

#include using namespace std; int main() { float num=0; float total=0; char symbol; cout << "Welcome to your friendly neighborhood accumulator! Please input your expression, one token at a time, starting with an operand and type in '=' when completed." << ' '; cin >> num; total=num; while(1){ cin >> symbol; switch(symbol){ case '+': cin >> num; total+=num; break; case '-': cin >> num; total-=num; break; } if(symbol=='='){ cout << total; break; } } return 0; }

Using a do-while loop. Recall that in a post-test loop, the loop body must execute once before the exit condition is checked. Therefore, to use a post-test loop, we have to change the way we implement the strategy. This can be done as follows:

initialize total as zero; initialize operator as +; read num; process num (add or subtract from total, depending on operator); read next operator; If (operator is =) exit and print total. read num; ... Translate this into C++ code, compile and test in a script session

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions