Connecting Tech Pros Worldwide Help | Site Map

program help (checkbook)

  #1  
Old July 19th, 2005, 06:56 PM
dan
Guest
 
Posts: n/a
can someone tell me how to have balance add the initial 10 dollars
just one time and not every time

thanks

int main()
{
double initial = 10, transaction;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision (2); // for 2 decimal place, because that is what
money uses

cout << "************Enter 0.00 to quit this
program************\n\n";
cout << "Initial balance: " << initial;
cout << endl;

double balance = 0;
double penalty = 0;
double invalid = 0;
do
{
cout << "\nEnter transaction amount: ";
cin >> transaction;
balance = balance + transaction + initial;
invalid = balance - transaction - initial;
if (balance >= 0)
{
cout << "Balance: " << balance;
cout << endl;
}
if ((balance < 0 && balance > -100))
{
cout << "Overdraw fee: $10.00\n";
penalty = balance - initial - 10;
cout << "Balance: " << penalty;
cout << endl;
}
if (balance < -100)
{

cout << "Insufficient funds to complete transaction.\n";
cout << "Balance: " << invalid;
cout << endl;
}
} while (transaction != 0.00); //sentinel value
cout << endl;
cout << "End of day balance: " << balance;

cout << endl << endl;
system ("pause");
return EXIT_SUCCESS;
}
  #2  
Old July 19th, 2005, 06:58 PM
David Rubin
Guest
 
Posts: n/a

re: program help (checkbook)


dan wrote:[color=blue]
>
> can someone tell me how to have balance add the initial 10 dollars
> just one time and not every time
>
> thanks
>
> int main()
> {
> double initial = 10, transaction;[/color]
[snip][color=blue]
> double balance = 0;[/color]

I think the intent is for the program to start with a balance of 10, so
replace the above lines with

double balance = 10.0;

Then...
[color=blue]
> do
> {
> cout << "\nEnter transaction amount: ";
> cin >> transaction;
> balance = balance + transaction + initial;[/color]

balance += transaction;

[snip][color=blue]
> if ((balance < 0 && balance > -100))
> {
> cout << "Overdraw fee: $10.00\n";[/color]
[snip]
balance -= 10;

[snip][color=blue]
> }
> if (balance < -100)
> {
>
> cout << "Insufficient funds to complete transaction.\n";[/color]
[snip][color=blue]
> }[/color]

cout << "Balance: " << balance << endl;
[color=blue]
> } while (transaction != 0.00); //sentinel value
> cout << endl;
> cout << "End of day balance: " << balance;
>
> cout << endl << endl;
> system ("pause");
> return EXIT_SUCCESS;
> }[/color]

BTW, using "0.00" to terminate input is not particularly user-friendly.
A more robust solution is to allow for alphanumeric input, and process,
e.g., 'q' to quit, and numbers as valid transactions. This requires only
a slightly more complex input method than you've got.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
  #3  
Old July 19th, 2005, 06:58 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: program help (checkbook)


dan wrote:
[color=blue]
> can someone tell me how to have balance add the initial 10 dollars
> just one time and not every time[/color]

I suggest posting a minimum complete program that demonstrates the
problem you are having. Extra, unrelated code just obscures the main
issue and lessens your chance of getting an accurate response. The FAQ
has recommendations for how to post code:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
OODB or RDB for checkbook/budget program? ringer answers 7 July 16th, 2009 01:59 AM
confused about behaviour of scanf Lalatendu Das answers 33 January 4th, 2006 05:35 AM
a C++ "workbook" mescaline answers 4 July 22nd, 2005 06:31 AM
Unification of Methods and Functions David MacQuigg answers 99 July 18th, 2005 12:28 PM