the scenario is like this~~~~~
an user of a bank wishes to access his/her account~~~~~
he/she is required to input their account number~~~~~
and the program will show their account balance according to their account number. (the acc. number with its corresponding acc. balance is stored in a text file)
and i come up to this problem~~~~~
when the user input their acc. number
the program will not output their acc. balances
can someone tells me how to solve this problem~~~~~
how to let the program knows that it need to output the acc. balance according to the responding acc. number~~~~~~
you must organise your data file in a specific manner, like
acc:balances
then you need to read out the file line by line and compare the acc. number with the one that the user provided. if they are same, then you can do some string processing work and extract the desired balances.
.... can i know what is the command line for reading the acc. number line by line~~~~~~
and what is the command line to extract the desired the desired balances~~~~~~
string useracc;
cin >> useracc; // get the user's acc
ifstream fin("in.txt"); // open the file
string line; // store each line of the file
while(getline(fin, str)) { // read a line
string::size_type pos; // record the ':' position
string acc = str.substr(0, pos = str.find(':')); // extract acc
string balance = str.substr(pos+1); // extract balance
if(acc == useracc) { // if they are equal
cout << balance; // report the balance
break; // and exit the loop
}
}
sorry~~~~i get it what you mean already~~~~~
after trying to work out my source code~~~~~~~
i finally know what you mean already~~~~~~jimmyi~~~~~
thanks~~~~~~~~~
this is the sample source code i've written~~~~~
can someone comment this source code~~~~~~
see that is there anything that can be modify to let it look more simplier~~~~~