10 Replies - 410 Views - Last Post: 23 May 2019 - 11:29 AM Rate Topic: -----

#1 Deadweight77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-May 19

Banking system

Posted 23 May 2019 - 06:27 AM

So I am trying to make a banking system that gives you choices on what you want. The problem is I want to enter in option 2 and look for existing accounts through a text document,but don't exactly know how to do it. For example, if I enter in an existing account named Jason it will say "Found account for Jason".
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void display(char& anwser);
void N_account(char& anwser,string & name);
bool Exist(string& name_search, char& anwser, string name_from_file);


int main()
{
	int start_money;
	string name, name_search, name_from_file;
	char anwser;
	display(anwser);
	N_account(anwser,name);
	Exist(name_search, anwser,name_from_file);
}

void display(char& anwser)
{
	cout << setw(65) << "=================" << endl;
	cout << setw(65) << "Banking Managment" << endl;
	cout << setw(65) << "=================" << endl;
	cout << setw(60) << "1.New account" << endl;
	cout << setw(65) << "2.Existing account" << endl;
	cout << setw(56) << "3.Deposit" << endl;
	cout << setw(57) << "4.Withdraw" << endl;
	cout << setw(62) << "5.Close account" << endl;
	cin >> anwser;
}

void N_account(char& anwser,string & name)
{
	if (anwser == '1')
	{
			ofstream outfile;
			outfile.open("Accounts.txt",std::ofstream::out|std::ofstream::app);
			cout << "Enter in first and last name for new account:";
			cin.ignore();
			getline(cin, name);
			outfile << name;
			outfile << '\n';
			cout << "Account added" << endl;
			outfile.close();

	}	
}

bool Exist(string & name_search,char & anwser,string name_from_file)
{
	if (anwser == '2')
	{
		ifstream infile;
		infile.open("Accounts.txt");
		cout << "Enter in your account:";
		cin.ignore();
		getline(cin, name_search);
		while (infile >> name_from_file)
		{
			if (name_from_file == name_search)
			{
				cout << "Account found: " << name_search << endl;
				return true;
			}
		}
		return false;
		infile.close();
		
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Banking system

#2 jimblumberg   User is offline

  • member icon

Reputation: 5732
  • View blog
  • Posts: 17,558
  • Joined: 25-December 09

Re: Banking system

Posted 23 May 2019 - 07:02 AM

Quote

For example, if I enter in an existing account named Jason it will say "Found account for Jason".

Okay, but isn't this what you want?

What happens when you enter some other "account" that doesn't exist?

Jim
Was This Post Helpful? 0
  • +
  • -

#3 Deadweight77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-May 19

Re: Banking system

Posted 23 May 2019 - 07:13 AM

If the account doesn't exist it will say "no account found" or something along those lines.

This post has been edited by Skydiver: 23 May 2019 - 07:55 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg   User is offline

  • member icon

Reputation: 5732
  • View blog
  • Posts: 17,558
  • Joined: 25-December 09

Re: Banking system

Posted 23 May 2019 - 07:16 AM

The question was, does it exhibit the above behavior?

What is the program actually doing that differs from what you want it to do?

Jim

This post has been edited by Skydiver: 23 May 2019 - 07:56 AM
Reason for edit:: Removed quote since I cleaned up the huge quote above this.

Was This Post Helpful? 0
  • +
  • -

#5 Deadweight77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-May 19

Re: Banking system

Posted 23 May 2019 - 07:18 AM

I would use the "else" statement to say "no account found", but I need the current "if" statement to work. For some reason it is not being acknowledged.

This post has been edited by Skydiver: 23 May 2019 - 07:56 AM
Reason for edit:: Remove unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5732
  • View blog
  • Posts: 17,558
  • Joined: 25-December 09

Re: Banking system

Posted 23 May 2019 - 07:57 AM

Quote

For some reason it is not being acknowledged.

What? You said: "if I enter in an existing account named Jason it will say "Found account for Jason".", so is this happening or not?

For further help you'll need to post a sample of your input file (inside code tags please).

Edit: By the way you may want to actually call that function with the proper parameter.

Jim

This post has been edited by jimblumberg: 23 May 2019 - 07:58 AM

Was This Post Helpful? 0
  • +
  • -

#7 Deadweight77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-May 19

Re: Banking system

Posted 23 May 2019 - 09:38 AM

Sorry for the confusion. What I meant was that I want to enter in an existing account and for the program to acknowledge it. The example I gave up top is what I want to do,but it is not working that way. So in other words the program is not going through the "If" statement. Here are some samples from my input file of existing accounts if this is what you've asked for.

John Doe
Jane Doe
Travis Scott
William Smith
Patrick Michaels



Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6929
  • View blog
  • Posts: 23,544
  • Joined: 05-May 12

Re: Banking system

Posted 23 May 2019 - 10:32 AM

This:
infile >> name_from_file


will only read a string until it encounters whitespace. So if your file contains:
John Doe



And you are searching for "John Doe", there will never be a matched because name_from_file will be "John", not "John Doe".
Was This Post Helpful? 0
  • +
  • -

#9 Deadweight77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-May 19

Re: Banking system

Posted 23 May 2019 - 11:08 AM

Oh! Ok that makes sense now. I just tried it and you're right. Surely there is a way to make it read the whole thing right? If so I'd like to know.
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg   User is offline

  • member icon

Reputation: 5732
  • View blog
  • Posts: 17,558
  • Joined: 25-December 09

Re: Banking system

Posted 23 May 2019 - 11:28 AM

Quote

Surely there is a way to make it read the whole thing right?

Yes there is, have you even tried to look up different input functions? Perhaps something like this may be of assistance?


Jim
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6929
  • View blog
  • Posts: 23,544
  • Joined: 05-May 12

Re: Banking system

Posted 23 May 2019 - 11:29 AM

Well, why are you using getlline(cin, name); instead of cin >> name; to read from the console input stream?

If your answer is because the name can have whitespaces, then there is your answer for how to read from the file stream.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1