Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Before looking at the code, could somebody please explain how to do these modifi

ID: 3650440 • Letter: B

Question

Before looking at the code, could somebody please explain how to do these modifications:

The program should work for both upper and lower case 'c' and 's'

Charges is an amount to be deducted from the account balance. Therefore, either subtract the charges out of balance or add the negative amount of the charges.

Here's the code:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
// declare the variables
int accountNumber;
double currentBalance, minimumBalance, charges = 0;
char accountType;

// User enters the account number
cout << "Enter account number: ";
cin >> accountNumber;

// User enters the account type
cout << "Enter account type: ";
cin >> accountType;

// User enters the minimum balance
cout << "Enter minimum balance: ";
cin >> minimumBalance;

// User enters the current balance
cout << "Enter current balance: ";
cin >> currentBalance;

// begin calculations
switch(accountType)
{
// Case: Savings Account
case 's' : if (currentBalance < minimumBalance)
charges = -10.00;
else if (currentBalance >= minimumBalance)
charges = currentBalance * 0.04;
break;

// Case: Checking Account
case 'c' : if (currentBalance < minimumBalance)
charges = -25.00;
else if (currentBalance <= minimumBalance + 5000)
charges = currentBalance * 0.03;
else if (currentBalance >= minimumBalance + 5000)
charges = currentBalance * 0.05;
break;

// Case: Invalid Accounts
default : cout << "Invalid current type";
exit(0);
} // end switch

cout << "Account number: " << accountNumber << endl;
cout << "Account type: " << accountType << endl;
cout << "Minimum balance: " << minimumBalance << endl;
cout << "Current balance: " << currentBalance << endl;

// this prints an appropriate message
cout << "Your current balance ";
if (charges < 0)
cout << "falls below the minimum balance and therefore"
<<" will need to pay a service charge of $" << -charges << endl;
else
cout << "is above the minimum balance and therefore"
<<" will receive an interest of $" << charges << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

Explanation / Answer

Please rate...

You can do this by attaching two cases together:

For example:

switch(ch)

{

      case 's': case 'S':

       .........

       .........

      break;

     case 'c': case 'C':

       .........

       .........

      break;

}

Modified Porgram:

=========================================================

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
// declare the variables
int accountNumber;
double currentBalance, minimumBalance, charges = 0;
char accountType;

// User enters the account number
cout << "Enter account number: ";
cin >> accountNumber;

// User enters the account type
cout << "Enter account type: ";
cin >> accountType;

// User enters the minimum balance
cout << "Enter minimum balance: ";
cin >> minimumBalance;

// User enters the current balance
cout << "Enter current balance: ";
cin >> currentBalance;

// begin calculations
switch(accountType)
{
// Case: Savings Account
case 's' :case 'S': if (currentBalance < minimumBalance)
charges = -10.00;
else if (currentBalance >= minimumBalance)
charges = currentBalance * 0.04;
break;

// Case: Checking Account
case 'c' : case 'C': if (currentBalance < minimumBalance)
charges = -25.00;
else if (currentBalance <= minimumBalance + 5000)
charges = currentBalance * 0.03;
else if (currentBalance >= minimumBalance + 5000)
charges = currentBalance * 0.05;
break;

// Case: Invalid Accounts
default : cout << "Invalid current type";
exit(0);
} // end switch

cout << "Account number: " << accountNumber << endl;
cout << "Account type: " << accountType << endl;
cout << "Minimum balance: " << minimumBalance << endl;
cout << "Current balance: " << currentBalance << endl;

// this prints an appropriate message
cout << "Your current balance ";
if (charges < 0)
cout << "falls below the minimum balance and therefore"
<<" will need to pay a service charge of $" << -charges << endl;
else
cout << "is above the minimum balance and therefore"
<<" will receive an interest of $" << charges << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote