Hello adeel zamann,
I have to start with what you mean by "
satisfied result"?
Your program has some problems beyond the fact that choice 2 needs a lot more work.
I would start with getting "choice" 1 to work before you move on.
If you have an input file to start with you need to post it, so everyonw can start with the same indformation.
The "Windows.h" header is not needed, but the "string" header file is.
You may want to consider defining "choice" as a "char" or an "int". Or as a string you could use
if (choice[0] == '1')
I rearranged the "cout " statement. You may find it easier to use:
1 2 3 4 5 6 7
|
cout <<
"\n"
" 1 For Create Account\n"
" 2 For Login Account\n"
" 3 For Exit\n"
" Enter Choice: ";
cin >> choice;
|
It produces the output of:
1 For Create Account
2 For Login Account
3 For Exit
Enter Choice:
|
I do not know if you want choice 3 or not.
ofstream accounts("accounts.txt", ios::app | ios::in | ios::out);
. In this the "iso::in" is not need and is ignored because the "o" in "ofstream" says it is for output, so you can not use it for input. The oposit is true for the "ifstream".
Writing to your output stream can be done in 1 line like this:
1 2 3 4
|
accounts
<< name << '\n'
<< password << '\n'
<< money << '\n';
|
Whether it is for input or output. When it comes to the name what are you expecting to be entered? The formatted
cin >> name
will take from the input buffer up to a white space or "\n" whichever comes first, so if you want a name with a space in it consider using "getline".
In choice 2 you read "money" as a string, but never convert into a numeric value. It is much more difficult to add to a string than it is to a numeric variable.
You could define "money" as an "int" or a "double" and read, write and input to a numeric variable. It would save on some coding.
There is a start for now.
Andy