Write a C++ program that asks users for two numbers and a choice of the following operations: addition, subtraction, multiplication, division or exit the program. The program then displays the result of chosen operations on the two numbers entered or terminates. Use one function to get two numbers, separate functions for each arithmetic operations (+, -, *, /), and one function to display the output. The program should continue running until the user chooses to exit.
The SWITCH STATEMENTS and IF ELSE STATEMENTS both do the same exact thing.
It's upon the programmer's choice on which one to use.
But if you use both of them simultaneously, then it will cause problems. This is the reason your program is not showing you the result.
So I suggest you get rid of the if statements and just use the switch statements.
The SWITCH STATEMENTS and IF ELSE STATEMENTS both do the same exact thing.
Not to be nitpicky, but this is incorrect. Not only are they often translated into machine code differently (barring the optimizer doing something clever), but the cases in switches are a lot more restrictive than the conditions in if-else chains. For instance, have you tried using a variable as one of the case conditions?
@whitenite1
The arguments are passed in by reference here. I would argue that it makes more sense to return the result, sure, but the result isn't lost, rather the sumAdd variable in main, having been passed by reference to the function, is changed, and that is then printed out back in main.