I've been trying for a while to create like an offline bank that will keep the amount of money each person has will be able to add or subtract money from the account and will have a personal account for each person that uses it.
Here is where my problem comes. How do I make my program create a text file every time some1 creates an account to keep their account's information there.
My code is the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream accounts;
string accName;
string STRING;
int choice;
ofstream regAcc;
string newAcc;
cout << "\tWelcome to the Offline Virtual Bank" <<endl;
cout << "Here you will be able to keep a constant record of what you have in your bank\naccount completely offline without";
cout << " the need of an internet connection.\n\n";
cout << "1-Login" <<endl;
cout << "2-Register" <<endl;
cout << "3-exit" <<endl;
cout << "To begin, what would you like to do: ";
cin >> choice;
switch (choice){
case 1:
system ("cls");
cout << "Now enter your login information: ";
cin >> accName;
accounts.open ("accounts.txt");
{
getline(accounts,STRING);
}
accounts.close();
if (STRING.compare(accName) == 0)
cout << "Welcome "<< accName << " what would you like to do" <<endl;
else
cout << "Sorry, invalid login information" <<endl;
break;
case 2:
cout << "What would you like your username to be (note:will be needed to login): ";
cin >> newAcc;
regAcc.open ("accounts.txt");
regAcc << newAcc;
regAcc.close();
cout << "Account registration successful. Restart the program to login with your new account." <<endl;
break;
case 3:
cout << "Thanks for using the Offline Virtual Bank, hope you come back later" <<endl;
cout << "Press enter to exit" << endl;
cin.ignore();
cin.ignore();
exit (1);
break;
}
cout << "Thanks for using the Offline Virtual Bank, hope you come back later" << endl;
cout << "Press enter to exit" << endl;
cin.ignore();
cin.ignore();
return 0;
}
|
I know its not complete (its missing a lot) but I'm stuck in the part where the user creates the account and the program creates a text file for that account currently also as u can see it uses accounts.txt that's the one I'm using while i figure a way to create a different one for each account.
the text file would be like example.txt for a user whose user name is example.
Is there any other way of doing this besides the way i did it? (im kind of new so i searched what i wanted and used different methods i found online)
if so what other ways can i use to create files based on what a user inputs?
Finally, if you need more information on what I exactly want or something similar tell me even though i think Ive explained quite well what i need.
(case 2 is the problem)