program help (checkbook)

D

dan

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;
}
 
D

David Rubin

dan said:
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; [snip]
double balance = 0;

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...
do
{
cout << "\nEnter transaction amount: ";
cin >> transaction;
balance = balance + transaction + initial;

balance += transaction;

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

[snip]
}
if (balance < -100)
{

cout << "Insufficient funds to complete transaction.\n"; [snip]
}

cout << "Balance: " << balance << endl;
} while (transaction != 0.00); //sentinel value
cout << endl;
cout << "End of day balance: " << balance;

cout << endl << endl;
system ("pause");
return EXIT_SUCCESS;
}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top