Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!