13 Replies - 13226 Views - Last Post: 06 April 2007 - 09:50 AM Rate Topic: -----

#1 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Banking Program Help

Posted 23 March 2007 - 09:47 AM

I need some help with a banking program. Here is the assignment:
Write a program to store and manage customer information for a bank. Customer information must be stored and updated using a file. The requirements for this assignment are as follows:

* Program must have a menu of all possible options for the user
* Program must store the name, account balance, and account number of each customer
* Option 1: The first option for the menu is "Create Account", this option allows the user to create a new account for a customer with a starting balance of zero and a new account number.
* Option 2: The second option on the menu should be "Deposit Money". This option should ask the user to input their account number, then allow them to deposit money and increase the account balance.
* Option 3: The third option is "Withdraw money". This option should ask the user for their account number then allow them to withdraw money and decrease the account balance.
* Option 4: The fourth option for the menu is to "View Account Balance". This option should allow the user to input their account number and be shown their current balance.
* Option 5: "View Customers". This option should allow the user input a secret number to see a list of all the customers and their balances.
* Option 6: The sixth option for the menu is to "Update and Exit". This option will write all the customer information to the file and end the program.
* When the program loads it reads in all previously created customer accounts


Here is my code so far:

#include <iostream>
#include <fstream>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
};

void createAccount{
	ofstream members;
	int balance;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> balance;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	};

int main (int argc, char * const argv[]) {		
	int input;	
	string tempname;
	int accountnumb = 59803;	
	do {
		cout << "Welcome to the Bank.\n Select an option.\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	}else if (input == 2){
	
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}



I get an error by the createAccount function declaration and when I call it. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Banking Program Help

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Banking Program Help

Posted 23 March 2007 - 12:13 PM

Is there a website where teachers get thier assignments from?

anyway. This must be a little confusing for your users:
	cout << "Enter the name for the account:\n";
	cin >> balance;
Ussualy when someone asks me for my account name I enter text not by balence... but if this means that next time my bank asks me for my account name I enter 100,000,000 and I am rich... well.

Other than that I can't see an error off hand, next time post the error as well.
Was This Post Helpful? 0
  • +
  • -

#3 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 23 March 2007 - 02:59 PM

Ok, fixed what NickDMax pointed out. I get these errors:

Banking.cpp:53:2: warning: no newline at end of file
Banking.cpp:11: error: invalid function declaration
Banking.cpp: In function ‘int main(int, char* const*)’:
Banking.cpp:38: error: ‘createAccount’ was not declared in this scope


Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Banking Program Help

Posted 23 March 2007 - 08:19 PM

LOL, well I found your problem and I am sorry I didn't catch it before.

this should compile, it gives some warnings, but they are just because you are still working.

#include <iostream>
#include <fstream>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
};

void createAccount();

int main (int argc, char * const argv[]) {		
	int input;	
	string tempname;
	int accountnumb = 59803;	
	do {
		cout << "Welcome to the Bank.\n Select an option.\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	}else if (input == 2){
	
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}

void createAccount()
{
	ofstream members;
	int balance;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> balance;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	return;
}


The problem was that you mixed the declaration and definition of createAccount. Ussualy the convention is that we declare the functions at the beginning and implement them below main. They must be declared before they are used and it helps to have main (often the meat of the program, and the entry point) at the beginning of the file.
Was This Post Helpful? 0
  • +
  • -

#5 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 24 March 2007 - 03:55 PM

Well, I did it on my own. Here is what I got:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
};

void createAccount(){
	//ofstream members;
	int balance;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	accountnumb ++;
'/a';
	};

int main (int argc, char * const argv[]) {		
	int input;	
	do {
		cout << "Welcome to the Bank.\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	}else if (input == 2){
	
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}


I guess I need to connect it to a file and make a vector of customers. Any hints would be appreciated, or I'm on to cplusplus.com!
Was This Post Helpful? 0
  • +
  • -

#6 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 24 March 2007 - 04:05 PM

Hmm... I am looking at classes. Would it be wise to combine my struct and function into one class? Also, I am having trouble finding how to make the program read data from a file and store it as variables. Any hints?
Was This Post Helpful? 0
  • +
  • -

#7 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 24 March 2007 - 09:14 PM

Here is some updated code. I'm just going to make all the functions and worry about vectors later. BTW, just a question - why do some people not use namespace std?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
};

void createAccount(){
	ofstream members;
	members.open ("members.txt");
	int balance = 0;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	accountnumb ++;
	members << name << "\n";
	members << balance << "\n";
	members << accountnumb << "\n";
	cout << "\n";
	members.close();
	};

int main (int argc, char * const argv[]) {		
	int input;	
	cout << "Welcome to the Bank.";
do {
		
		cout<< "\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	}else if (input == 2){
	
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#8 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 24 March 2007 - 09:35 PM

Ok, here is my really updated code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
};

void createAccount(){
	ofstream members;
	ofstream numb;
	numb.open ("numb.txt");
	int balance = 0;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	accountnumb ++;
	numb << accountnumb;
	numb.close();
	
	members.open ("members.txt");
	members << name << "\n";
	members << balance << "\n";
	members << accountnumb << "\n";
	cout << "\n";
	members.close();
	};

void



int main (int argc, char * const argv[]) {		
	int input;	
	cout << "Welcome to the Bank.";
do {
		
		cout<< "\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	}else if (input == 2){
	
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}



I'm getting two errors:
Banking.cpp:39: error: two or more data types in declaration of ‘main’
Banking.cpp:39: error: ‘::main’ must return ‘int’


Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Banking Program Help

Posted 24 March 2007 - 09:50 PM

Remove "const" from your main declaration.
int main (int argc, char *argv[]) {


And you need to remove the word "void" you have floating before your main function.
	members.close();
	};

//void	//Delete this line



int main (int argc, char * const argv[]) {   

Was This Post Helpful? 0
  • +
  • -

#10 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 26 March 2007 - 07:57 AM

Well the assignment says I need to use a vector. How could I go about doing this? I have read cplusplus.com's tutorial on them but I don't quite get it. I would really appreciate another explanation. Thanks.
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Banking Program Help

Posted 26 March 2007 - 07:57 PM

Well a vector is basicly a fancy array, at least that is how many progammers use it. The nice thing about a vector is that data can be dynamicly addded or removed from the vector.

Suppose I wanted to use a vector to hold a collection of records:
struct member{
	string name;
	double balance;
	int number;
};

vector<member> memDirectory;
member memInfo;

for (int i=0; i<MAXMEMBERS; ++i)
{
   cin >> memInfo.name >> memInfo.balence >> memInfo.number;
   memDirectory.push_back(memInfo);
}

(of course the above code would not compile w/o more structure)
This would create a data table in memory of the current members. If I wanted to look for a particular member memDirectory[num] would return a particular entry (though using the at() function is safer). Rather than using the push_back function I might have used the insert function... I like this function because it I like to have my data nice and sorted and it makes writing a routine to insert new items into a sorted list easy (as opposed to an array where you have to copy all entries past the insertion point up one).
Was This Post Helpful? 0
  • +
  • -

#12 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 27 March 2007 - 03:59 PM

Ok, so I did away with all of the file i/o (it wasn't really the direction the assignment needed to go). I updated my code to work with the vector better.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
}newmember;

void createAccount(){
	
	int balance = 0;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	
	newmember.name = name;
	newmember.balance = balance;
	newmember.number = accountnumb;
	};




int main (int argc, char*argv[]) {		
	int input;	
	vector<member>membervector;
	cout << "Welcome to the Bank.";
do {
		
		cout<< "\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
	
	
	if (input == 1){
		createAccount();
	membervector.push_back (newmember);
	}else if (input == 2){
	cout << newmember;
	}
	else if (input == 3){}
	
	else if (input == 4){}
	
	else if (input == 5){}
	
	else{}
	
	} while (input != 6);
	
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#13 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 06 April 2007 - 09:26 AM

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
}newmember;

void createAccount(vector<member> &members){
	
	int balance = 0;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	
	newmember.name = name;
	newmember.balance = balance;
	newmember.number = accountnumb;
	
	members.push_back(newmember);
	
	
}
void deposit(vector<member> &members){
	
	int amount;
	int accountnumber;
	
	cout<< "What's your account number?\n";
	cin >> accountnumber;
	
	
	for (int i = 0; i<members.size(); i++ ){
		if (members[i].number == accountnumber){
			cout << "Alright, ya whino. How much do you wanna deposit.\n";
			cin >> amount;
			
			members[i].balance += amount;
			
			cout << "Your new balance is:" << members[i].balance << "\n";
			
		}
	}
	
	
}




int main (int argc, char*argv[]) {		
	ofstream memberfile;
	int input;	
	int newbala;
	vector<member> membervector;
	memberfile.open ("members.txt");
	cout << "Welcome to the Bank.";
	do {
		
		cout<< "\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
		
		
		if (input == 1){
			createAccount(membervector);
			
		}else if (input == 2){
		deposit;
		}
		else if (input == 3){}
		
		else if (input == 4){}
		
		else if (input == 5){}
		
		else{}
		
	} while (input != 6);
	
	cout << "Thanks for using the bank!";
	memberfile.close();
	return 0;
}

This post has been edited by Captain M: 06 April 2007 - 09:27 AM

Was This Post Helpful? 0
  • +
  • -

#14 Captain M  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 103
  • Joined: 21-January 07

Re: Banking Program Help

Posted 06 April 2007 - 09:50 AM

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

struct member{
	string name;
	double balance;
	int number;
}newmember;

void createAccount(vector<member> &members){
	
	int balance = 0;
	string name;
	int accountnumb = 59803;
	cout << "Enter the name for the account:\n";
	cin >> name;
	cout << "Your starting balance is $0.\n";
	cout << "Your account number is " << accountnumb << ".\n";
	
	newmember.name = name;
	newmember.balance = balance;
	newmember.number = accountnumb;
	
	members.push_back(newmember);
	
	
}
void deposit(vector<member> &members){
	
	int amount;
	int accountnumber;
	
	cout<< "What's your account number?\n";
	cin >> accountnumber;
	
	
	for (int i = 0; i<members.size(); i++ ){
		if (members[i].number == accountnumber){
			cout << "Alright, ya whino. How much do you wanna deposit.\n";
			cin >> amount;
			cin.ignore();
			
			members[i].balance += amount;
			
			cout << "Your new balance is: " << members[i].balance << "\n";
			
		}}}
		
void withdraw(vector<member> &members){
	
	int deposit;
	int accountnumber;
	
	cout<< "What's your account number?\n";
	cin >> accountnumber;
	
	
	for (int i = 0; i<members.size(); i++ ){
		if (members[i].number == accountnumber){
			cout << "Alright, ya whino. How much do you wanna withdraw?\n";
			cin >> deposit;
			cin.ignore();
			
			members[i].balance -= deposit;
			
			cout << "Your new balance is: " << members[i].balance << "\n";
			}
			else{
			cout << "Invalid account number, ya whino.\n Try again.\n";
			}
			}
			}
			
			
void display(vector<member> &members){

	int accountnumber;
	
	cout<< "What's your account number?\n";
	cin >> accountnumber;
	
	
	for (int i = 0; i<members.size(); i++ ){
		if (members[i].number == accountnumber){
			
			//cout << members[i];
	
			
			
			}}}
			
	




int main (int argc, char*argv[]) {		
	ofstream memberfile;
	int input;	
	int newbala;
	vector<member> membervector;
	memberfile.open ("members.txt");
	cout << "Welcome to the Bank.";
	do {
		
		cout<< "\n Select an option.\n ============================\n";
		cout << "	1- Create an account\n";
		cout << "	2- Make a deposit\n";
		cout << "	3- Make a withdrawl\n";
		cout << "	4- View account balance\n";
		cout << "	5- View customers\n";
		cout << "	6- Update and exit\n";
		cin >> input;
		
		
		if (input == 1){
			createAccount(membervector);
			
		}else if (input == 2){
		deposit (membervector);
		}
		else if (input == 3){
		withdraw (membervector);
		}
		else if (input == 4){}
		
		else if (input == 5){}
		
		else{}
		
	} while (input != 6);
	
	cout << "Thanks for using the bank!";
	memberfile.close();
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1