In this lab, you complete a partially written c++ program that includes a function that returns a value. the program is a simple calculator that prompts the user for two numbers and an operator ( +, -, *, or / ). the two numbers and the operator are passed to the function where the appropriate arithmetic operation is performed. the result is then returned to the main()function where the arithmetic operation and result are displayed. for example, if the user enters 3, 4, and *, the following is displayed: 3 * 4 = 12

the source code file provided for this lab includes the necessary variable declarations and input and output statements. comments are included in the file to you write the remainder of the program.

instructions

write the c++ statements as indicated by the comments.
execute the program by clicking the run button at the bottom of the screen.

draft:

// calculator.cpp - this program performs arithmetic, ( +. -, *. / ) on two numbers.
// input: interactive
// output: result of arithmetic operation

#include
#include

using namespace std;

// write performoperation() function declaration here

int performoperation(double numberone, double numbertwo, string op);
int main()
{
double numberone, numbertwo;
string operation;
double result;
cout < < "enter the first number: ";
cin > > numberone;
cout < < "enter the second number: ";
cin > > numbertwo;
cout < < "enter an operator (+*,/): ";
cin > > operation;

// call performoperation method here

result = performoperation(numberone,numbertwo,operation);
cout < < numberone;
cout < < " " < < operation < < " ";
cout < < numbertwo;
cout < < " = ";
cout < < result < < endl;
return 0;
} // end of main() function

// write performoperation function here
int performoperation(double numberone, double numbertwo,std: : string(op)){
double result;
if (op == "+")
result = numberone + numbertwo;
else if (op == "-")
result = numberone - numbertwo;
else if (op == "*")
result = numberone*numbertwo;
else if (op == "/")
result = numberone/numbertwo;
else
cout< < "wrong input. try again.";
return result;
}

it's already working but it says that there's something wrong with the declared performoperation

Solved
Show answers

Ask an AI advisor a question