Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- cout << fixed << showpoint << setprecision(2);
- char action; // Deposit, Withdrawal, Interest, and Closeout
- int initialBalance; // initial balance entered by the user must be between 1 and 1000
- int Amount; // this is my second operand
- int numBillsDispensed; // the number of bills dispensed
- float newBalance; // the balance after the action has taken place
- bool isInvalid = false;
- cout << "Enter the initial balance [1-1000]: " << endl;
- cin >> initialBalance;
- cout << "Enter an action (D, W, I or C): " << endl;
- cin >> action;
- cout << "Enter the second operand: " << endl;
- cin >> Amount;
- if (action == 'D')
- {
- if (Amount > 1000 || Amount < 1)
- {
- cout << "Input out of range" << endl;
- isInvalid = true;
- }
- if (isInvalid == false)
- {
- newBalance = initialBalance + Amount;
- cout << "The new account balance is " << newBalance << endl;
- }
- }
- if (action == 'W')
- {
- if (Amount < 1 || Amount > initialBalance)
- {
- cout << "Input out of range" << endl;
- isInvalid = true;
- }
- if (isInvalid == false)
- {
- newBalance = initialBalance - Amount;
- cout << "The new account balance is " << newBalance << endl;
- }
- }
- if (action == 'I')
- {
- if (Amount < 1 || Amount > 15)
- {
- cout << "Input out of range" << endl;
- isInvalid = true;
- }
- if (isInvalid == false)
- {
- newBalance = (float)initialBalance + (((float)Amount / 100.0)*(float)initialBalance);
- cout << "The new account balance is " << newBalance << endl;
- }
- }
- if (action == 'C')
- {
- if (Amount != 20 && Amount != 10 && Amount != 5)
- {
- cout << "Input out of range" << endl;
- isInvalid = true;
- }
- if (isInvalid == false)
- {
- numBillsDispensed = initialBalance / Amount;
- newBalance = initialBalance - (numBillsDispensed * Amount);
- cout << numBillsDispensed << " bills dispensed plus " << newBalance << endl;
- }
- }
- if (action != 'D' && action != 'W' && action != 'I' && action != 'C')
- {
- cout << "Input out of range" << endl;
- isInvalid = true;
- }
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement