Hello. I am an IT major at Arkansas Tech University. I just began programming this semester. I have been given an assignment to give a bank customer certain information about their account and charges. So here is a shortened version of the question:

There are two types of accounts: Checking and Savings. Every customer must maintain a minimum balance. If a customer's balance falls below the minimum balance, there is a service charge of $10.00 for savings accounts and $25.00 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:
A) savings accounts receive 4%.
B) checking accounts with balances of up to $5,000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.
Write a program that reads a customer's account number, account type, minimum balance that the account should maintain, and current balance. The program should output the account number, account type, current balance, and an appropriate message.

I know this is not a "do my homework" online community. I have worked on this program and cannot figure out what keeps happening. Any help will be appreciated. Thank you. I am new in this forum, but I guess I just post my code here:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

float minBal, balance, actNum, checking, saving;

char actType;

int main()
{
	cout << "What is your account number?" << endl;
	cin >> actNum;
	cout << endl;
	
	cout << "Is it a checking(C) or savings(S) account?" << endl;
	cout << "Press C for checking or S for savings (make sure to capitalize)." << endl;
	cin >> actType;
	cout << endl;
	
	cout << "What is your minimum balance?" << endl;
	cin >> minBal;
	cout << endl;
	
	cout << "What is your current balance?" << endl;
	cin >> balance;
	cout << endl;
	
checking = 25.00;
saving = 10.00;

	if (actType == 'C' || actType == 'c')
	{
		if (balance < minBal)
		{
			cout << "You have a service charge of $" << checking;
			cout << " for falling below your minimum balance of " << minBal << '.' << endl;
		}
	    {
		    if (minBal + 5000 <= balance)
			{
				cout << setw(15) << left << "Account Number" << setfill(' ');
				cout << setw(20) << right << "Type" << setfill(' ');
				cout << setw(20) << right << "Balance" << setfill (' ');
				cout << endl;
			
				cout << setw(15) << left << actNum << setfill (' ');
				cout << setw(20) << right << "Checking" << setfill(' ');
				cout << setw(20) << right << '$' << balance << setfill(' ');
				cout << endl << "Your interest is 3%" << endl << endl;
			
				cout << "Thank you for choosing our bank." << endl;
			}
		}
	}
	
	if (actType == 'S' || actType == 's')
	{
		if(balance < minBal)
		{
			cout << "You have a service charge of $" << saving;
			cout << " for falling below your minimum balance of $" << minBal;
			cout << endl;
		}
		{
			cout << setw(15) << left << "Account Number" << setfill(' ');
			cout << setw(20) << right << "Type" << setfill(' ');
			cout << setw(20) << right << "Balance" << setfill (' ');
			cout << endl;
			
			cout << setw(15) << left << actNum << setfill (' ');
			cout << setw(20) << right << "Savings" << setfill(' ');
			cout << setw(20) << right << '$' << balance << setfill(' ');
			cout << endl << "Your interest if 4%" << endl << endl;
			
			cout << "Thank you for choosing our bank." << endl;
		}
	}
	
	
	return 0;
}

Recommended Answers

All 3 Replies

>>I have worked on this program and cannot figure out what keeps happening.

You will need to explain the problem in more detail if you expect any help. What is the program doing that it is not supposed to do?

Is there a reason for the { on line 40?

First of all a good attempt to write this code. Congrats!

Just a few comments-
1) Isn't the minimum balance a constant meaning that it is something that you set not that the user enters?
2) I think you forgot to deal with the 5 percent case. Why not assign a variable for the interest rate and have an if statement decide which number to set it at
Ex-

if (balance <= minbal + 5000){
intrstrt = 5%;
}
else if (balance > 5000 + minbal){
intrstrt = 3%;
}

etc.

If you give some more details that would be great.

Thank you both for your input on the problem. A friend and I looked over this problem together for about an hour last night and was able to get it executing properly. If you are wondering what the finished code looks like and what it does, I'm going to post the finished code as well. Once again, thank you both for assisting me with my question.

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

float minBal, balance, actNum, checking, saving;

char actType;

int main()
{
	cout << "What is your account number?" << endl;
	cin >> actNum;
	cout << endl;
	
	cout << "Is it a checking(C) or savings(S) account?" << endl;
	cout << "Press C for checking or S for savings (make sure to capitalize)." << endl;
	cin >> actType;
	cout << endl;
	
	cout << "What is your minimum balance?" << endl;
	cin >> minBal;
	cout << endl;
	
	cout << "What is your current balance?" << endl;
	cin >> balance;
	cout << endl;
	
checking = 25.00;
saving = 10.00;

	if (actType == 'C' || actType == 'c')
	{
		if (balance < minBal)
		{
			cout << "You have a service charge of $" << checking;
			cout << " for falling below your minimum balance of " << minBal << '.' << endl;
		}
	    {
		    if (minBal + 5000 >= balance)
			{
				cout << setw(15) << left << "Account Number" << setfill(' ');
				cout << setw(20) << right << "Type" << setfill(' ');
				cout << setw(20) << right << "Balance" << setfill (' ');
				cout << endl;
			
				cout << setw(15) << left << actNum << setfill (' ');
				cout << setw(20) << right << "Checking" << setfill(' ');
				cout << setw(20) << right << '$' << balance << setfill(' ');
				cout << endl << "Your interest is 3%" << endl << endl;
			
				cout << "Thank you for choosing our bank." << endl;
			}
			if (minBal + 5000 < balance)
			{
				cout << setw(15) << left << "Account Number" << setfill(' ');
				cout << setw(20) << right << "Type" << setfill(' ');
				cout << setw(20) << right << "Balance" << setfill (' ');
				cout << endl;
			
				cout << setw(15) << left << actNum << setfill (' ');
				cout << setw(20) << right << "Checking" << setfill(' ');
				cout << setw(20) << right << '$' << balance << setfill(' ');
				cout << endl << "Your interest is 5%" << endl << endl;
			}
		}
	}
	
	if (actType == 'S' || actType == 's')
	{
		if(balance < minBal)
		{
			cout << "You have a service charge of $" << saving;
			cout << " for falling below your minimum balance of $" << minBal;
			cout << endl;
		}
		{
			cout << setw(15) << left << "Account Number" << setfill(' ');
			cout << setw(20) << right << "Type" << setfill(' ');
			cout << setw(20) << right << "Balance" << setfill (' ');
			cout << endl;
			
			cout << setw(15) << left << actNum << setfill (' ');
			cout << setw(20) << right << "Savings" << setfill(' ');
			cout << setw(20) << right << '$' << balance << setfill(' ');
			cout << endl << "Your interest if 4%" << endl << endl;
			
			cout << "Thank you for choosing our bank." << endl;
		}
	}
	
	
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.