You are to implement in your "calculator" program, functions
(preferably value returning and passing arguments) for each
math section
of your program. So, the Addition, subtraction, etc. will be a function. Also, you
will add the switch statement control structure as part of your menu
selection so that the user can select
which operation he/she wants to perform and go to that function on your
program. The user
will be able to go to any section of your program with a main menu such as
the one below.
You will have your program setup similar to:
switch (choice)
'a' : call your add function.
's' : call your subtractions function.
.
.
'x': out of the program
You will have a function to read the values for the operation and pass those
values as parameters to your function.Think about what implementation would be
most effective, reducing the size of your current code, such as if the reading
of the input values should
take place inside of the function or before or inside the switch statement.
Avoid repetition of code, meaning that if you see parts of code that repeat
on your program most likely you will use functions. For instance the
feedback for correctness of the user's answer " you got it right x ? x
is ?"
it will repeat in several parts of your program, so this would be a function
call.
You will have the menu in a loop so that the user will have the choice to do as many
calculations as he/she wishes by making the selection on the menu. So,
every time that the user does an addition for example. It will go back to
the main menu and allow the user to make a new selection.
The user will perform the addition for instance, then the result will be displayed and
the menu would show up on the screen again for another choice until user selects x
to exit.
Your code should be much shorter than the previous assignments, if you
notice that your code is longer, it probably means that you are not making enough
use of functions on your program.
Note : Please do not implement commands that have not
been covered in class. This calculator assignment is progressive in difficulty and
implementation. The challenge is to implement a section at a time, using just what we have
learned during the previous weeks. For instance, if we have learned
functions, do not use classes. You are to use functions, otherwise points will be
deducted.
Clear Screen (CLS)
Here is how you clear your screen in Visual C++
First, include stdlib.h at the top of your program. Then, just insert the
following call whenever you want to clear the screen.
system("CLS");
- or -
system("cls"); // The command is not case sensitive.
The program below is an example of how to use this method of clearing the
screen
Note You must have the "endl" after the cout, or it will
not work.