RE: What do you guys think, pseudo code attempt

  • From: "Joseph Lee" <joseph.lee22590@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 28 Jun 2010 12:18:56 -0700

Hi,
The code seems nice here. Only thing I'd like to add is just one more
variable to store the remaining balance. So, if we translate this into C++,
it becomes (only the main algorithm is done; hope someone can provide other
versions in other languages...
// The four variables (for now, we'll use integers):
int current_balance; // The checking account balance at the start of the
month.
int deposit; // The deposit amount.
int withdrawl; // The amount withdrawn.
int remaining_balance; // The balance at the end of the month.
cout << "Please type your current balance:" << endl;
cin >> current_balance;
cout << "How much did you deposit during the month:" << endl;
cin >> deposit;
cout << "How much did you withdraw:" << endl;
cin >> withdrawl;
// Now, add the deposit to the current balance and subtract withdrawl.
// Note: Be sure to check that the money left after this operation is not a
negative number!
// For sake of previews, I'll provide two versions: a regular calculation
and a function.
// Version A: Regular one...
remaining_balance = current_balance + deposit - withdrawl;
if (remaining_balance < 0)
cout << "Oops, you've used more than your account..." << endl;
else
cout << "You have $" << remaining_balance << "remaining." << endl;
// Version B: Using the calculation as a function...
// In other words, we'll provide a shortcut, or a name of a function, which
will perform the above code.
// This version would be a preview for you:
int calculate_balance(int cb, int d, int w)
{
int r; // The remaining balance.
R = cb+d-w;
Return (r);}
// Now, the main part...
// After the user enters all the info...
R = calculate_balance(current_balance, deposit, withdrawl);
// After that, the "if" statement will come up and check for errors.
The reason I tried both versions is to illustrate that the problem can be
solved using so many ways. In addition to the two methods described here, we
can come up with literally hundreds of ways of doing this, including
creating more complicated functions that will also check the error for you
within a function, creating an actual check object (this is called a class)
and so on.
Hope this helps...
Cheers,
Joseph P.S. As always, please come up with your own code... (mostly for
academic integrity...).

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jes
Sent: Monday, June 28, 2010 11:17 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: What do you guys think, pseudo code attempt

Hi all,
Here is an attempt  at filling out an IPO chart, and putting in some pseudo
code within the processing items. Let me know your thoughts. The following
also contains two desk-checks.

Output: display user's checking account balance at the end of the month.
Input: Three pieces of info: His checking account balance at the start of
the month, money deposited into his account during the month, and  money
withdrawn from his account during the month.

Processing:
Algorithm:

First main function, Print message asking user for each piece of
information. Used to help computer accomplish the user's goal.
Create three separate variables:
A variable for storing beginning checking account balance.
A  variable for storing deposits.
A  variable to store withdrawal.
each variable should be created after user inputs data, and should be in the
same order as the messages which are displayed.
on the screen for each piece of information.

Finally, process all variables to get new account balance, and display the
information on the screen to the user.

First desk-check
checking account balance at the beginning of the month:
2000
money deposited during the month:
775
money withdrawn during the month:
1200
Result: New balance = 1575.

second desk-check:
checking account balance at the beginning of the month:
500
money deposited during the month:
100
money withdrawn during the month:
610
Result: -10
Something is wrong with the second desk-check. What is it?

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.439 / Virus Database: 271.1.1/2967 - Release Date: 06/28/10
06:37:00

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: