I'm having trouble with a program with class.

When it runs, on the screen and on the file it shows one output, the last one in the input file. It USED to work, untill I tried to get fancy and add some other code... that will be below the main block of code. I would like to make the bottom one work if I can. I don't want to 'cheat' but any other code types (something other than while?) would be greatly appreciated!

Here is my algorithm:

Declare constants: CHECK_FEE = 25, SAVINGS_FEE = 10, CHECKING_TOP_LIMIT = 5000, CHECK_LOW_INTEREST = .03,
CHECK_HIGH_INTEREST = .05, SAVING_INTEREST = .04
Declare ints: AccountNumber, MinimumBlanace
Declare doubles: InputBalance, FinalBalance
Declare char: AccountType

Loop starts here, ends when number goes above 5 (user inputted number
read external file
store first number as AccountNumber
store next character as AccountType
store next number as MinimumBlanace
store next number as InputBalance

If character is 'S' or 's'
if InputBalance is less than MinimumBlanace, charge SAVINGS_FEE against account, store result in InputBalance.
else, contunue the program.

if InputBalance is equal to or is higher than MinimumBalance, apply SAVING_INTEREST to account.
store result as FinalBalance.
else
store InputBalance as FinalBalance.

output results

If character is 'C' or 'c'
if InputBalance is less than MinimumBlanace, charge CHECK_FEE against account, store result in InputBalance.
else, contunue the program.

break

if InputBalance is equal to or is higher than MinimumBalance do:
{if InputBalance is in between MinimumBlanace and CHECKING_TOP_LIMIT, then interest CHECK_LOW_INTEREST is applied to account.
Store new result as FinalBalance}
else interest applied to InputBalance is CHECK_HIGH_INTEREST, store new result as FinalBalance.
else
store InputBalance as FinalBalance.

If neither output error message.

output results
loop to 'read external file' until finished with file

input file:

46728 S 1000 2700
87324 C 1500 7689
79873 S 1000 800
89832 C 2000 3000
98322 C 1000 750

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

using namespace std;

const double CHECK_FEE = 25, SAVINGS_FEE = 10, CHECKING_TOP_LIMIT = 5000, CHECK_LOW_INTEREST = .03;
const double CHECK_HIGH_INTEREST = .05, SAVING_INTEREST = .04;




void main()
{
	int AccountNumber, loop, loopEnd;
	double InputBalance, MinimumBlanace, FinalBalance, CheckTopLimit;
	char AccountType;

	ofstream fout;
	ifstream fin;
	
	fin.open("bankdata.nf0");
	fout.open("bankdataout.nf0", ios::app);
	cout << "Please enter the amount of accounts that will be updated for this month." << endl; 
	cin >> loopEnd;
	for(loop = 0; loop < loopEnd; loop++) 
	{
		fin >> AccountNumber >> AccountType >> MinimumBlanace >> InputBalance;
		switch(AccountType) // Depending on the AccountType variable, one of three choices will be made.
		{
			case 's': // If AccountType is a 's' or 'S' run below commands.
			case 'S':
			if (InputBalance < MinimumBlanace) // If starting balance is less than minimum balance, apply fee. 
				InputBalance = InputBalance - SAVINGS_FEE;
			else // If starting balance is not less than minimum balance, apply interest.
				InputBalance = (SAVING_INTEREST * InputBalance) + InputBalance;
			FinalBalance = InputBalance;
			break;
			case 'c': // If AccountType is a 'c' or 'C' run below commands.
			case 'C':
			if (InputBalance >= MinimumBlanace) // If account balance is less than or equal to, run below commands.
			{
				CheckTopLimit = CHECKING_TOP_LIMIT + MinimumBlanace;
				if (InputBalance <= CheckTopLimit) // If account balance is or is less than the checking top limit, apply
					InputBalance = (InputBalance * CHECK_LOW_INTEREST) + InputBalance; 			// lower interest rate.
				else // If account is more than the checking top interest, apply higher interest rate.
					InputBalance = (InputBalance * CHECK_HIGH_INTEREST) + InputBalance;
			}
			else // If the account balance is not greater than the minimum balance, apply fee.
				InputBalance = InputBalance - CHECK_FEE;
				FinalBalance = InputBalance;
			break;
			default:
				cout << "You entered the wrong account type. Please check input file.";	
			}
		} // end of correct/false account type. 


		fout << fixed << showpoint << setprecision(2);
		fout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" << setw(22) << "NEW CURRENT BALANCE" << endl;
		fout << setw(15) << AccountNumber << setw(14) << AccountType << setw(22) << FinalBalance << endl;
		fout << endl  << endl << endl << endl;

		cout << fixed << showpoint << setprecision(2);
		cout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" << setw(22) << "NEW CURRENT BALANCE" << endl;
		cout << setw(15) << AccountNumber << setw(14) << AccountType << setw(22) << FinalBalance << endl;
		cout << endl << endl << endl << endl;

	fout.close();

	fin.close();	
	cout << "Press Enter to end the program.";
	cin.ignore();
	cin.ignore();
}

Varient:

// Get file input, preform calculations, output results to file and screen.

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

using namespace std;

const double CHECK_FEE = 25, SAVINGS_FEE = 10, CHECKING_TOP_LIMIT = 5000, CHECK_LOW_INTEREST = .03;
const double CHECK_HIGH_INTEREST = .05, SAVING_INTEREST = .04;




void main()
{
	int AccountNumber, loop, loopEnd;
	double InputBalance, MinimumBlanace, FinalBalance, CheckTopLimit;
	char AccountType;
	bool validAccount = false;

	ofstream fout;
	ifstream fin;
	
	fin.open("bankdata.nf0"); 
	fout.open("bankdataout.nf0");
	while (validAccount == false) // if false, re-run data.
	{
	cout << "Please enter the amount of accounts that will be updated for this month." << endl; 
	cin >> loopEnd;
		for(loop = 0; loop < loopEnd; loop++) 
		{
	
			if (validAccount == false)  
			{
				fin >> AccountNumber >> AccountType >> MinimumBlanace >> InputBalance;
				switch(AccountType) // Depending on the AccountType variable, one of three choices will be made.
				{
					case 's': // If AccountType is a 's' or 'S' run below commands.
					case 'S':
						if (InputBalance < MinimumBlanace) // If starting balance is less than minimum balance, apply fee. 
							InputBalance = InputBalance - SAVINGS_FEE;
						else // If starting balance is not less than minimum balance, apply interest.
							InputBalance = (SAVING_INTEREST * InputBalance) + InputBalance;
						FinalBalance = InputBalance;
						validAccount = true;
						break;
					case 'c': // If AccountType is a 'c' or 'C' run below commands.
					case 'C':
						if (InputBalance >= MinimumBlanace) // If account balance is less than or equal to, run below commands.
						{
							CheckTopLimit = CHECKING_TOP_LIMIT + MinimumBlanace;
							if (InputBalance <= CheckTopLimit) // If account balance is or is less than the checking top limit, apply
								InputBalance = (InputBalance * CHECK_LOW_INTEREST) + InputBalance; 			// lower interest rate.
							else // If account is more than the checking top interest, apply higher interest rate.
								InputBalance = (InputBalance * CHECK_HIGH_INTEREST) + InputBalance;
						}
						else // If the account balance is not greater than the minimum balance, apply fee.
							InputBalance = InputBalance - CHECK_FEE;
						FinalBalance = InputBalance;
						validAccount = true;
						break;
				}
			}
			else 
				cout << "You entered the wrong account type. Please check input file.";	
		} // end of correct/false account type. 


		fout << fixed << showpoint << setprecision(2);
		fout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" << setw(22) << "NEW CURRENT BALANCE" << endl;
		fout << setw(15) << AccountNumber << setw(14) << AccountType << setw(22) << FinalBalance << endl;
		fout << endl  << endl << endl << endl;

		cout << fixed << showpoint << setprecision(2);
		cout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" << setw(22) << "NEW CURRENT BALANCE" << endl;
		cout << setw(15) << AccountNumber << setw(14) << AccountType << setw(22) << FinalBalance << endl;
		cout << endl << endl << endl << endl;

		fout.close();
	} // end of enter data loop.
	fin.close();	
	cout << "Press Enter to end the program.";
	cin.ignore();
	cin.ignore();
}

/* 



Checking
has Minimum balance, is variable.
	if balance is too low, there is a 25.00 fee.
	else, no fee.

	also, if blanace is or above minimun, interest is applied: 
	inbetween minimum balance and 5000, then interest is 3%
	else it is 5%


Savings
has Minimum balance, is variable.
	if balance is too low, there is a 10.00 fee.
	else, no fee.
	
	if blanace is the minimum blance or above
		then 4% interest



*/

/*
Declare constants: CHECK_FEE = 25, SAVINGS_FEE = 10, CHECKING_TOP_LIMIT = 5000, CHECK_LOW_INTEREST = .03, 
CHECK_HIGH_INTEREST = .05, SAVING_INTEREST = .04
Declare ints: AccountNumber, MinimumBlanace
Declare doubles: InputBalance, FinalBalance
Declare char: AccountType

read external file
	store first number as AccountNumber
	store next character as AccountType
	store next number as MinimumBlanace
	store next number as InputBalance
	
	If character is 'S' or 's'
		if InputBalance is less than MinimumBlanace, charge SAVINGS_FEE against account, store result in InputBalance.
		else, contunue the program.
		
		if InputBalance is equal to or is higher than MinimumBalance, apply SAVING_INTEREST to account.
		store result as FinalBalance.
		else
		store InputBalance as FinalBalance.
		
		output results
		
	If character is 'C' or 'c'
		if InputBalance is less than MinimumBlanace, charge CHECK_FEE against account, store result in InputBalance.
		else, contunue the program.
		
		break
		
		if InputBalance is equal to or is higher than MinimumBalance do:
			{if InputBalance is in between MinimumBlanace and CHECKING_TOP_LIMIT, then interest CHECK_LOW_INTEREST is applied to account.
			Store new result as FinalBalance}
			else interest applied to InputBalance is CHECK_HIGH_INTEREST, store new result as FinalBalance.
		else
		store InputBalance as FinalBalance.
		
		output results
	
	If neither output error message.
	loop to 'read external file' until finished with file




*/

Could u write a paragraph describing what exactly this code is supposed to do....

then I could help u

This program is supposed to take input from a file, for a bank. First is the account number, next is the checking or savings type, the minimum balance, and then the account balance. Depending upon the account type and balance amount different interest will be applied.

I think I'm going to 're-write' the code (copy paste, but do it piece by piece until it works... then save each revision! It worked before, but I screwed up the nesting. I think.)

Thank you for the reply too! Heh, the program was due earlier today, but I don't really mind. I can get it in next week.

Ok, I've been doing some work one the code. I don't like posting all of that at once (... and I jsut read the sticky! I read the one about school work, but not that one ^^) so I found something that converts C++ to HTML, and put it on a Google website.

Here is the code, Revision 3


When this is run, here is the (From the above input) output:

ACCOUNT NUMBER ACCOUNT TYPE NEW CURRENT BALANCE
46728 S 2808.00


ACCOUNT NUMBER ACCOUNT TYPE NEW CURRENT BALANCE
46728 S 2808.00


ACCOUNT NUMBER ACCOUNT TYPE NEW CURRENT BALANCE
46728 S 2808.00


ACCOUNT NUMBER ACCOUNT TYPE NEW CURRENT BALANCE
46728 S 2808.00


ACCOUNT NUMBER ACCOUNT TYPE NEW CURRENT BALANCE
46728 S 2808.00

I think the problem has something to do with the main for and while statements. I want it to loop x number of times, and it does. But it outputs the same data each time.

I just had an idea that I'll give a try... not what the professor wants, but I don't care really.

EDIT:

Oh, my, duh.

It looped alright. and the while was set to go past if true... and at the end of each correct thing, I set it as True! So it looped and outptted the same data five time! Duh!

baka.

Duh!

Ok, I think I have a better clue now.

One thing, which may or may not be a problem, is this

if (validAccount == false) {
  .....
  switch(AccountType) {
     case 's':
     case 'S':
        ....
        validAccount = true;
      ...

   }
 }
 else
   cout << "You entered the wrong account type. Please check input file.";

Now the first time you enter the switch case for your first account that you read from the file, you are setting validAccount to true, this means that it won't process any more elements and exit with the message " You entered the wrong account type. Please check input file"

I would think, you'd want to add an default case to your switch statement to check for any invalid account formats. You really don't need this "if (validAccount == false)" .

http://codingforcplus.googlepages.com/revision4

I got it to work! Here was my solution:
I set the value as true after each time it was correct, in the case sections. If it was not correct, the case would catch it.

But if it was correct, it continues on to display, and then at the end of the display it is set to false... locked. So then it is able to re-start, until the value of loopEnd was reached.

I might try something else, to make it prettier, but it works now! Bed now :D

I might try something else, to make it prettier, but it works now! Bed now

I just woke up from my ...bed :D :D so i guess to late....

int main()
{
	int AccountNumber, loop, loopEnd;
	double InputBalance, MinimumBlanace, FinalBalance, CheckTopLimit;
	char AccountType;
	bool validAccount = false;

	ofstream fout;
	ifstream fin;

	fin.open("bankdata.nf0"); 
	fout.open("bankdataout.nf0");


	while (validAccount == false) 
	{
		cout << "Please enter the amount of accounts" 
                       << "that will be updated for this month." << endl; 
		cin >> loopEnd;
		for(int i=1; i<=loopEnd; i++)
		{	
			fin >> AccountNumber >> AccountType 
                            >> MinimumBlanace >> InputBalance;
			switch(AccountType) 
			{
			case 's':
			case 'S':
				{
					if (InputBalance < MinimumBlanace) 
					InputBalance = InputBalance
                                              - SAVINGS_FEE;
					else
					InputBalance = (SAVING_INTEREST
                                             * InputBalance) 
                                             + InputBalance;
					FinalBalance = InputBalance;
					validAccount = true;
					break;
				}
			case 'c':
			case 'C':
				{
					if (InputBalance >= MinimumBlanace)
					{
						CheckTopLimit = CHECKING_TOP_LIMIT 
                                                      + MinimumBlanace;
						if (InputBalance <= CheckTopLimit)
						InputBalance = (InputBalance 
                                                      * CHECK_LOW_INTEREST) 
                                                      + InputBalance; 			
						else 
						InputBalance = (InputBalance 
                                                      * CHECK_HIGH_INTEREST)
                                                      + InputBalance;
					}
					else
					InputBalance = InputBalance - CHECK_FEE;
					FinalBalance = InputBalance;
					validAccount = true;
					break;
				}
			default:
				{
					validAccount = false;
					break;
				}

			} 





			fout << fixed << showpoint << setprecision(2);
			fout << setw(15) << "ACCOUNT NUMBER" 
                              << setw(14) << "ACCOUNT TYPE" 
                              << setw(22) << "NEW CURRENT BALANCE" 
                              << endl;
			fout << setw(15) << AccountNumber 
                              << setw(14) << AccountType 
                              << setw(22) << FinalBalance 
                              << endl;
			fout << endl  << endl << endl << endl;

			cout << fixed << showpoint 
                              << setprecision(2);
			cout << setw(15) << "ACCOUNT NUMBER" 
                               << setw(14) << "ACCOUNT TYPE"
                               << setw(22) << "NEW CURRENT BALANCE" 
                               << endl;
			cout << setw(15) << AccountNumber 
                               << setw(14) << AccountType
                               << setw(22) << FinalBalance 
                               << endl;
			cout << endl << endl << endl << endl;
		}

	}
	fout.close();
	fin.close();	
	cout << "Press Enter to end the program.";
	cin.ignore();
	cin.ignore();
	return 0;
}

This worked.

mmmmm
r u sure this code executes without problems???

I would say in general yes... but with visual studio 08 not so sure......

It worked in Visual 2008 express. I reposed the code to the website... maybe I made a copy mistake.


And chococrack, I don't quite understand what you did. Can you explain it? I don't want to just take the code you gave me without learning anything. I want to know why mine did not work!

And thank all of you for the quick replies!

hi again
make some patience I am working on a solution to your problem :D

The title of this thread:

....(For a class)

combined with the fact that the advantage of C++ over C is the OOP made me to decide to help by providing a OO solution using classes to your problem :D

Here it is together with some small description:


This program applies either FEES or INTERESTS to a specified number of bank accounts depending on the account’s starting balance in relationship to its minimum balance.

A "LoadAccountdata.nf0" file containg the following data:
• AccountNumber
• AccountType
• MinimumBalance
• InputBalance
Its format:

46728 S 1000 2700
87324 C 1500 7689
79873 S 1000 800
89832 C 2000 3000
98322 C 1000 750


  • The new balance for each account.
  • An output file: „SaveAccountdata.nf0” where the updated accounts can be found.

Simple main Implementation:

int main()
{
int n; //number of of accounts to be updated
std::cout<<"Please enter the amount of accounts"<<std::endl;
std::cout<<"that will be updated for this month:"<<std::endl;
std::cin>>n;
//Create only the required number of accounts for update
CAccountData accountsToUpdate(n);
//Get the accounts from the input file
accountsToUpdate.deserialize(n,"LoadAccountdata.nf0");
//Save the updated account into the output file
accountsToUpdate.serialize(n,"SaveAccountdata.nf0");
return 0;
}

And finally the whole code without errors nor warnings:

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

const double CHECK_FEE = 25;
const double SAVINGS_FEE = 10;
const double CHECKING_TOP_LIMIT = 5000;
const double CHECK_LOW_INTEREST = .03;
const double CHECK_HIGH_INTEREST = .05;
const double SAVING_INTEREST = .04;

class CAccountData
{
public:
	//Constructor with no arguments
	CAccountData() : 
	_accountNumber(0),_accountType(),_minimumBalance(0),_inputBalance(0),
	_finalBalance(0.0),_checkTopLimit(0.0),_validAccount(true),
	_noOfAccountsToBeUpdated(0) {}

	//Constructor with 1 argument: the number of accounts that are going to be updated
	CAccountData(int n):
	_accountNumber(0),_accountType(),_minimumBalance(0),_inputBalance(0),
	_finalBalance(0.0),_checkTopLimit(0.0),_validAccount(true),
	_noOfAccountsToBeUpdated(n) 
	{
			theAccounts = new CAccountData[n];
	}

	void showDataAfterAccountUpdate() 
	{
		//shows the data after the account has been  updated based on its type
		std::cout << std::fixed << std::showpoint << std::setprecision(2);
		std::cout << std::setw(15) << "ACCOUNT NUMBER" << std::setw(14) 
			<< "ACCOUNT TYPE" << std::setw(22) << "NEW CURRENT BALANCE" << std::endl;
		std::cout << std::setw(15) << _accountNumber << std::setw(14) 
			<< _accountType << std::setw(22) << _finalBalance << std::endl;
		std::cout << std::endl;
	}

	void serialize(int n,const char* filename) 
	{
		//Serializes n CAccountData data members into a file
		
		std::fstream   outputfile(filename,std::ios::app);
		for (int k=0;k<n;++k)
		{
			outputfile<< std::fixed << std::showpoint 
					  << std::setprecision(2);
			outputfile<< std::setw(15) << "ACCOUNT NUMBER" 
				      << std::setw(14) << "ACCOUNT TYPE" 
					  << std::setw(22) << "NEW CURRENT BALANCE" 
					  << std::endl;
			outputfile<< std::setw(15) << theAccounts[k]._accountNumber 
				      << std::setw(14) << theAccounts[k]._accountType 
					  << std::setw(22) << theAccounts[k]._finalBalance 
					  << std::endl;
			outputfile<< std::endl;
		}

		outputfile.close();
	}

	void deserialize(int n,const char* filename) 
	{
		//Deserializes n CAccountData from a file
		std::ifstream inputfile;
		inputfile.open(filename);
		for (int k =0;k<n;++k)
		{
			inputfile>>theAccounts[k]._accountNumber >> theAccounts[k]._accountType 
				>> theAccounts[k]._minimumBalance >> theAccounts[k]._inputBalance;
			theAccounts[k].UpdateBalance();
			if (theAccounts[k]._validAccount==false)
			{
				std::cout<<"ERROR: Invalid Account type found->EXIT"<<std::endl;
				std::cout<<"Find and correct the invalid account"<<std::endl;
				std::cout<<"type in the 'LoadAccountdata.nf0' file"<<std::endl;
				break;
			}
			theAccounts[k].showDataAfterAccountUpdate();
		}
		inputfile.close();
	}

	void UpdateBalance () 
	{	
		//Updates the balance based on the type
		
		if (_accountType=='s'||_accountType=='S')
		{
			// If starting balance is less 
			// than minimum balance, apply fee. 
			if (_inputBalance < _minimumBalance)
			{
				_inputBalance -= SAVINGS_FEE;
			}
			// If starting balance is not less 
			// than minimum balance, apply interest.
			else	
			{
				_inputBalance += (SAVING_INTEREST * _inputBalance);
			}
		}
		// If AccountType is a 'c' or 'C' run below commands.
		else if (_accountType=='c'||_accountType=='C')
		{
			if (_inputBalance >= _minimumBalance)
			{
				_checkTopLimit = CHECKING_TOP_LIMIT + _minimumBalance;
				// If account balance is or is less 
				// than the checking top limit, apply
				if (_inputBalance <= _checkTopLimit) 
				{
					// lower interest rate.
					_inputBalance += (_inputBalance * CHECK_LOW_INTEREST);           
				}
				// If account is more than the checking 
				// top interest, apply higher interest rate.
				else
				{
					_inputBalance += (_inputBalance * CHECK_HIGH_INTEREST);
				}
			}
			// If the account balance is not greater 
			// than the minimum balance, apply fee.
			else
			{
				_inputBalance -= CHECK_FEE;
			}
		}
		//An invalid account type has been read!!!->EXIT!!"
		else
		{
			_validAccount=false;
		}
		_finalBalance = _inputBalance;  
	}

protected:
	int _accountNumber;
	char _accountType;
	double _minimumBalance;
	double _inputBalance;
	double _finalBalance;
	double _checkTopLimit;
	bool _validAccount;
	int _noOfAccountsToBeUpdated;
	CAccountData* theAccounts;
};

int main()
{
	int n; //number of of accounts to be updated
	std::cout<<"Please enter the amount of accounts"<<std::endl; 
	std::cout<<"that will be updated for this month:"<<std::endl; 
	std::cin>>n;
	//Create only the required number of accounts for update
	CAccountData accountsToUpdate(n);
	//Get the accounts from the input file
	accountsToUpdate.deserialize(n,"LoadAccountdata.nf0");
	//Save the updated account into the output file
	accountsToUpdate.serialize(n,"SaveAccountdata.nf0");
	return 0;
}

Some notes:
A. If u wonder why I keep using

std::cout
or std::endl e.t.c

instead of simply using:

using namespace std;

read mine and Narues post in this thread:
http://www.daniweb.com/forums/post714791.html#post714791

B. The important functions are the serialize and the deserialize for reading/writing the data from/to files.

C. I had an even more simple version without using

CAccountData* theAccounts;

, however then, I could not get the serialize to work for all acounts... but only for the last...

TOGGLE PLAIN TEXT TO SEE THE CODE IN A CLEAR WAY , BECAUSE THERE ARE MANY LOOPS AND THE INDENTING GOES FAR... :d :d

I've gotten the program to be how I like it! Sorry I took so long, but if you are interested, here is the code:

// CPSC 111 10.07.08 Assignment #4
// Paul Little III
// Program File: shell.cpp

// Get file input, preform calculations, output results to file and screen.

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

using namespace std;

const double CHECK_FEE = 25, SAVINGS_FEE = 10, CHECKING_TOP_LIMIT = 5000;
const double CHECK_LOW_INTEREST = .03, CHECK_HIGH_INTEREST = .05, SAVING_INTEREST = .04;

void main()
{
   int AccountNumber, loop, loopEnd;
   double InputBalance, MinimumBlanace, FinalBalance, CheckTopLimit;
   char AccountType;
   bool validAccount = true;
   bool test = false;

   ofstream fout;
   
   fout.open("bankdataout.nf0", ios::app);
   
   // Allows user to set a loop for a certian number of times.
   cout << "Please enter the amount of accounts that will be updated for this month." << endl; 
   cin >> loopEnd;
   for(loop = 0; loop < loopEnd; loop++) 
   {   
      // To input data if validAccount bool is true.
      if(validAccount == true)
      {
         cout << "Please enter the Account number, Account type, Minimum balance, and "
             << "current balance, each seperated by a space." << endl;
         cin >> AccountNumber >> AccountType >> MinimumBlanace >> InputBalance;
         validAccount = false, test = false;
      }
	  // To input data if test is true
      if(test == true)
      {
         cout << "Is this data correct? (1 for yes, 0 for no.)" << endl;
         cout << fixed << showpoint << setprecision(2);
         cout << setw(15) << "Account Number" << setw(22) << "Minimum Blanace" 
             << setw(22) <<"Starting Balance" << endl;
         cout << setw(15) << AccountNumber << setw(22) << MinimumBlanace 
             << setw(22) << InputBalance << endl;
         cin >> test;
			// To input full data if test bool is false
            if(test == false)
            {
               cout << "Please enter the Account number, Account type, Minimum balance, "
                   << "and current balance, each seperated by a space." << endl;
               cin >> AccountNumber >> AccountType >> MinimumBlanace >> InputBalance;
               validAccount = false;
            }
			// To input only account type if test bool is true.
            else
            {
               cout << "Please enter the account type (C for checking, S for savings.)" << endl;
               cin >> AccountType;
            }
      }
	  // Switch depending on the AccountType variable, one of three choices will be made.
      switch(AccountType) 
      {
         case 's': // If AccountType is a 's' or 'S' run below commands.
         case 'S':
		    // If starting balance is less than minimum balance, apply fee. 
            if (InputBalance < MinimumBlanace)
               InputBalance = InputBalance - SAVINGS_FEE;
            // If starting balance is not less than minimum balance, apply interest.
			else
               FinalBalance = (SAVING_INTEREST * InputBalance) + InputBalance;
            FinalBalance = InputBalance;
            validAccount = true;
            break;
         case 'c': // If AccountType is a 'c' or 'C' run below commands.
         case 'C':
			// If account balance is less than or equal to, run below commands.
            if (InputBalance >= MinimumBlanace)
            {
               CheckTopLimit = CHECKING_TOP_LIMIT + MinimumBlanace;
			   // If account balance is or is less than the checking top limit, apply lower interest rate.
               if (InputBalance <= CheckTopLimit)
                  InputBalance = (InputBalance * CHECK_LOW_INTEREST) + InputBalance; 
			   // If account is more than the checking top interest, apply higher interest rate.
               else
                  InputBalance = (InputBalance * CHECK_HIGH_INTEREST) + InputBalance;
            }
			// If the account balance is not greater than the minimum balance, apply fee.
            else
               InputBalance = InputBalance - CHECK_FEE;
            FinalBalance = InputBalance;
            validAccount = true;
            break;
		 // If Account type is neither S or C, give error message. 
         default:
            cout << "The value you entered for the account type was incorect." 
			     << "Please check your data." << endl;
            cout << endl << endl;
            loop--;
            test = true, validAccount = false;
      }
	  // If account it valid, allow to output data.
      if(validAccount == true)
      {
         fout << fixed << showpoint << setprecision(2);
         fout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" 
		      << setw(22) << "NEW CURRENT BALANCE" << endl;
         fout << setw(15) << AccountNumber << setw(14) << AccountType 
		      << setw(22) << FinalBalance << endl;
         fout << endl  << endl << endl << endl;

         cout << fixed << showpoint << setprecision(2);
         cout << setw(15) << "ACCOUNT NUMBER" << setw(14) << "ACCOUNT TYPE" 
		      << setw(22) << "NEW CURRENT BALANCE" << endl;
         cout << setw(15) << AccountNumber << setw(14) << AccountType 
		      << setw(22) << FinalBalance << endl;
         cout << endl  << endl << endl << endl;
      }
   }
      
   fout.close();
   cout << "Press Enter to end the program.";
   cin.ignore();
   cin.ignore();
}
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.