Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this program with FUNCTION, not loop. write a program to model a simple c

ID: 3622190 • Letter: I

Question

I need this program with FUNCTION, not loop.

write a program to model a simple calculator. Each data line should consist of the next operation to be performed from the list below and the right operand. Assume the left operand is the accumulator value (initial value of 0). You need a function scan_data with two output parameters that returns the operator and right operand scanned form a data line. You need a function do_next_op that performs the required operation, do_next_op has two input parameters (the operator and operand) and one input/output parameter (the accumulator). The valid operators are:

+ add
- subtract
* multiply
/ divide
^ power (raise left operand to power of right operand)
q Quit

Your calculator should display the accumulator value after each operation. A sample
Run follows.

+ 5.0
Result so far is 5.9
^ 2
Result so far is 25.0
/ 2.0
Result so far is 12.5
q 0
final result is 12.5

Explanation / Answer

please rate - thanks

 

sorry about that, you should have said it doesn't have the function, not it doesn't work--I would have fixed it--I missed the need for the function

I really am not reading this post correctly-sorry again

 

#include <iostream>
#include <cmath>
using namespace std;
void do_next_op(char,double,double&);
void scan_data(char&, double&);
int main()
{double accum=0;
char op;
double num;
scan_data(op,num);
while(op!='q')
   {
    do_next_op(op,num,accum);
     cout<<"Result so far is "<<accum<<endl;
     scan_data(op,num);
     }
cout<<"Final result is "<<accum<<endl;
system("pause");
return 0;
}
void scan_data(char& op ,double& num)
{cin>>op;
cin>>num;
}
void do_next_op(char op,double num,double& accum)
{switch(op)
   {case '+': accum+=num;
            break;
    case '-': accum-=num;
            break;
    case '*':accum*=num;
            break;
    case '/': accum/=num;
            break;
     case '^': accum=pow(accum,num);
            break;
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote