I am having issues figuring out where to start in an assignment I was given. I'm currently taking Programming I for C++ and my professor can be very hard to understand at times so I typically self teach. The instructions for the assignment are below. If someone wouldn't mind helping me get to a good starting point or explaining the different points to me so I can better understand, that would be awesome. My class uses Visual Studio. Thank you!
Write a C++ program with a function that will perform arithmetic operations (addition, subtraction, multiplication, and division) and return the result to the caller. The function should be defined with three constant parameters.
The first two will be reference parameters of double type. These will serve as the operands
The third reference parameter (a character type) will serve as the operator
The return type should be double
Read operands and operators in the main function and call the function to do the operation. The result retuned must be displayed with appropriate message. The program should terminate when 0s are read for the operands.
For example, if the user enters
10.5 20 +
The main program should read and call the function with these three arguments. The function must return the result as 30.5. The main function must produce the following output
Start it like any other program. Start with your main function. First, you are going to need to get the user input. So set up the 3 variables (2 doubles, 1 char) and set up the statements to get the users input. After this, you can start setting up the function. As it says you will be passing the variables as constants and by reference. Inside the function, you'll need a simple if/if else statements to test the char you passed which will tell you whether you will be doing addition, subtraction, multiplication, and division. From there, you do the math and return the result. Back in main, you will output the result.
If there is a specific spot you are stuck at please be more specific.
Okay so I realized what Joe had said and misunderstood. I have put together my if statement now how would I code in the equations after to get the desired answers?
Don't forget that a function which takes the operator and operand as parameters, and returns a double ( the answer) is required to perform the calculations.
Also a switch control inside the function is a good way to improve on the cascade of if statements.
http://www.cplusplus.com/doc/tutorial/control/