Hello everybody! This is my project for my fundamentals of programming class. I was wondering how I would be able to output "Invalid input entered" or something like that when the user enters a bad input like letters or symbols. I assumed that when it reads the letters, it takes the ASCII number of the first letter as the value and stores that in balance or checks but that's not what happens, it always outputs "The bank's service fees for this month are $25.00" no matter what letter or symbol I input. I tried using the trailing else to catch these bad inputs but it does not work. Here is the prompt to the project:
A bank charges $10 per month plus the following check fees for a commercial checking
account:
$0.10 each for fewer than 20 checks
$0.08 each for 20-39 checks
$0.06 each for 40-59 checks
$0.04 each for 60 or more checks
The bank also charges an extra $15 if the balance of the account falls below $400
(before any check fees are applied).
Write a program that asks for the beginning balance and the number of checks written.
Compute and display the bank's service fees for the month.
Input validation: Do not accept a negative value for the number of checks written.
If a negative value is given for the beginning balance, display an urgent message
indicating the account is overdrawn.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//define a list of vars & input
int checks;
double balance, bankFees;
cout << setprecision(2) << fixed << showpoint;
cout << "Please enter the beginning balance of your account: $";
cin >> balance;
cout << "Please enter the number of checks written: $";
cin >> checks;
//processing
if (balance < 0)
{
balance = false;
cout << "Your account is overdrawn!\n";
}
else if (balance < 400)
{
balance = true;
bankFees = 15;
}
else if (balance >= 400)
{
balance = true;
bankFees = 0;
}
else
cout << "Invalid input entered.";
if (checks >= 60 && balance)
{
bankFees += checks * .04 + 10;
cout << "The bank\'s service fees for this month are $" << bankFees;
}
else if (checks >= 40 && balance)
{
bankFees += checks * .06 + 10;
cout << "The bank\'s service fees for this month are $" << bankFees;
}
else if (checks >= 20 && balance)
{
bankFees += checks * .08 + 10;
cout << "The bank\'s service fees for this month are $" << bankFees;
}
else if (checks < 20 && checks >= 0 && balance)
{
bankFees += checks * .10 + 10;
cout << "The bank\'s service fees for this month are $" << bankFees;
}
else if (checks < 0)
cout << "Number of checks entered has to be greater than 0.\n";
else
cout << "Invalid input entered.";
return 0;
}
|