After the switch statement I have to place the request for the withdrawal amount in a do loop and keep asking for an amount until an amount less than or equal to the account balance has been entered. Negative numbers are a form of deposit. It's nott suppose to keep asking How much to withdrawl. The user should just be able to keep entering numbers until its less than or equal to the account.
Code:
// Dones, Crystal
// CSC*125 R
// ATM
#include <iostream>
using namespace std;
int main()
{
char account;
long long balance = 0;
long long withdrawal = 0;
do
{
cout << "Greetings, Mr. Paulson." << endl << endl;
cout << "Checking" << endl;
cout << "Savings" << endl;
cout << "TARP" << endl;
cout << endl;
cout << "From which of the above accounts would you like to make a withdrawal? (c/s/t)? ";
cin >> account;
cout << endl;
system ("cls");
} while (account != 'C' && account != 'c' && account != 's' && account != 'S' && account != 't' && account != 'T');
if (account == 'C' || account == 'c' || account == 's' || account == 'S' || account == 't' || account == 'T');
{
switch(account)
{
case 'c': balance = 1000;
cout << "You have $" << balance << " in your checking account." << endl;
break;
case 'C': balance = 1000;
cout << "You have $" << balance << " in your checking account." << endl;
break;
case 's': balance = 10000;
cout << "You have $" << balance << " in your savings account." << endl;
break;
case 'S': balance = 10000;
cout << "You have $" << balance << " in your savings account." << endl;
break;
case 't': balance = 700000000000;
cout << "You have $" << balance << " in your TARP account." << endl;
break;
case 'T': balance = 700000000000;
cout << "You have $" << balance << " in your TARP account." << endl;
break;
}
for (int count = 1; count <= account; count++)
{
cout << endl;
cout << "How much would you like to withdraw? $";
cin >> withdrawal;
}
cout << endl;
if (withdrawal < 0)
cout << "Sorry, negative withdrawals are not allowed." << endl;
else if (withdrawal > balance)
cout << "Sorry, that amount is not available." << endl;
else
cout << "You have $" << balance - withdrawal << " left." << endl;
cout << endl << endl;
system("pause");
return 0;
}
}
Bookmarks