Connecting Tech Pros Worldwide Help | Site Map

program help (checkbook)

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 05:56 PM
dan
Guest
 
Posts: n/a
Default program help (checkbook)

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, 05:58 PM
David Rubin
Guest
 
Posts: n/a
Default 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, 05:58 PM
Kevin Goodsell
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.