Ok. Let's get down to basics.
First, you'll need two declare two
shorts
or two
doubles
for the containers that will hold
the checking and saving's accounts total money
depending on if you prefer to use floating-point numbers,
truncation, the whole math rounding off bit, etc.
Call one Checking and the other Savings.
Now declare two separate functions above the main function.
Make it a void, call it whatever you want, but leave it blank
(hence, it's a prototype). The blank functions above should look something like this:
1 2
|
void CheckingsTotal();
void SavingsTotal();
|
We are using these two small function prototypes so that we can
change the control block of the execution of the program so
that later when we call the function we will execute it and have it
display the amount of money is available depending on whether the
user selects Savings or Checkings.
Now as for the logic
if else
part, assuming you've never really used
if
statements
or are inexperienced somewhat, the
if
statement is
just a logical way of determining if something is TRUE or FALSE
or EQUAL, LESSER or GREATER. Whether it's true or false we will follow the appropriate commands based on what the user's
selection was against the statement. In this case, we will
have two logical things to take against the statement: checking or savings, correct?
We create a
string
and declare it just like every other container:
string choice;
This will hold the logical choice that you will make based whether you want checking or savings.
Use the basic input/output console window code:
cin >>
and
cout <<
Have the user perform a
cin >> choice;
right before the
if
statement begins so that we can test the choice against the statement's comparison, like this:
1 2 3 4 5 6 7
|
cin >> choice;
if(choice == "checking") // <-- Meaning if you entered "checking" and hit enter.
{
CheckingsTotal(); // If "choice" was input "checking", the statement WAS in fact TRUE and you'll be taken to the "CheckingsTotal" function which
//will contain the appropriate code to print the Checking's value
//based on the amount you gave the Checking's data type.
}
|
After this, just basically copy it but with the value of SAVINGS instead of checking.
Are you with me so far?