![beyattatsymbal123](/avatars/16893.jpg)
beyattatsymbal123
14.12.2019 •
Computers and Technology
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
More tips
- F Family and Home How to Build a Strong Relationship with Your Child: Tips for Effective Communication...
- H Health and Medicine Boosting Immunity: A Complete Guide on How to Improve Your Body’s Natural Defenses...
- C Computers and Internet The Best Antivirus Programs for your PC...
- S Style and Beauty How to Get Rid of Acne: Scientifically Proven Methods...
- H Health and Medicine Simple Ways to Lower Cholesterol in the Blood: Tips and Tricks...
- O Other How to Choose the Best Answer to Your Question on The Grand Question ?...
- L Leisure and Entertainment History of International Women s Day: When Did the Celebration of March 8th Begin?...
- S Style and Beauty Intimate Haircut: The Reasons, Popularity, and Risks...
- A Art and Culture When Will Eurovision 2011 Take Place?...
- S Style and Beauty How to Choose the Perfect Hair Straightener?...
Answers on questions: Computers and Technology
- C Computers and Technology What type of switch is installed to control a luminaire from two different control points? How many switches are needed and what type are they?...
- M Mathematics Which is closest to -1? -0.28, -4/5, -1/5, -0.82...
- M Mathematics Subtract. write answer in simplest form 5/6-1/6...
- H History Why did germany fail to win the battle of britain?...
- H Health Sam wants to get a credit card. how would a strong credit history be a benefit to him? a)he would know his credit rating.b)he would have a higher credit limit.c)he would be able...
- M Mathematics How do i solve this and what property do i use?...
- M Mathematics Write an equation of the line that passes through both points and has the given slope slope is 2 and (-1, 1)...
- M Mathematics Sue s teacher asked her to find 426 divided by 10 how many places and in what direction should sue move the decimal point to get the correct quotient...
- M Mathematics Robby goes to the supermarket to buy a bag of chips. he brings $20 to the store and pays $3.79 for the chips. on the way home, he finds $1.35 in coins on the sidewalk. how much money...
- S Social Studies What parallels do you see in our society from the 1960s and today...
Ответ:
In the given program the function work properly and the code for remainder section calculation can be given as:
Code:
This code is written inside the function in conditional statement block
else if (op == "%") //check condition
result = numberOne % numberTwo; //holds value in result variable.
Explanation:
The description of the code can be given as:
In the given program a function "performOperation" is defined that accepts three variable in which two values is number and one is sign value inside a function in the conditional statement section we add code for calculating remainder that can be defined above. This function will calculate a value and return the value. In the main method, we declare a variable that is "numberOne, numberTwo, and operation" these three variables are used to take input from the user and passed into the function. To hold function return value we define a variable that is the result that holds function value and prints its value.Ответ:
i do
Explanation: