This is the Question and following is my program. Could someone please help with it. I'm not getting anywhere. It keep giving the 2065 error code -- "cout is undeclared Identifier at the functions".
Modify Lab Five such that you use functions for each math calculation (Add, Subtract, Multiply, and Divide). Pass in parameters to each function for the values to use and the functions will return the result. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean – true if the operator is valid, false if not valid. This function will have two parameters. First is a string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid.
It keeps giving the error code 2065. Also I haven't plugged in the Multiplication function ad Divide Function. I just want to make sure first i get add and subtract, right. Please Help.
The Program runs ask for the Operator and the second number but for some minor mistake it doesn't add or subtract. and ask for second number twice before giving the result. And when Press 'C' it clears and doesn't ask for operator.
I personally hate dislike constructs like line 125. They are ugly & non-scalable, and best handled with a switch. They are especially not needed just prior a switch which does the same thing.
The code would benefit from a IsOperator function that returns a bool, rather repeating these tests throughout the code.
This is the psuedocode for a basic calculator:
1 2 3 4
//get number
//get operator
//get number
//calc & print answer
Looking at this, 185 LOC is too much, and it only does + and - so far. Remember to check for division by zero when you do that function. Be careful doing that with doubles - you really want to check whether the number is less than some arbitrary precision like 0.001 say.
You also have global variables, put them all in main() and send them to functions that need them as references.
You can also make use of the toupper function (which transforms a char to upper case) so you don't have to test variables twice.