This is my first time learning C++ and I have a small problem with my code. I would appreciate any help. The issue is whenever I enter a negative value for my balance and it prompts with the number of checks, the "if" code runs else as well after input of checks , so I have to put it twice every time. What am I doing wrong here? Disregard the variables as they will be changed once I can figure this out.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int perMonth = 10.0, balanceFee = 15.0;
double checks = 0, balance;
double fees = 0;
cout << "Enter the following information about your checking account. \n";
cout << "Beginning balance: ";
cin >> balance;
if (balance < 0)
{
cout << "Your account is overdrawn! \n";
cout << "Balance has to be greater than 0. \n";
cout << "Number of checks written: ";
cin >> checks;
}
else
cout << "Number of checks written: ";
cin >> checks;
if (balance < 400)
fees = balanceFee;
cout << showpoint << fixed << setprecision(2);
if (checks >= 0 && checks < 20)
cout << "The bank fee this month is $" << .10 * checks + perMonth + fees << endl;
else if (checks >= 20 && checks <= 39)
cout << "The bank fee this month is $" << .08 * checks + perMonth + fees << endl;
else if (checks >= 40 && checks <= 59)
cout << "The bank fee this month is $" << .06 * checks + perMonth + fees << endl;
else if (checks >= 60)
cout << "The bank fee this month is $" << .04 * checks + perMonth + fees;
else
cout << "Can't do that! \n";
I also tried nesting the if statement with the balance < 400 in the first if statement and i get the same result. Can someone please explain to me what mistakes I made?