helllo everyone,
i am writing a C++ program using ifstream. There will be two text file_ one with balance of the customer's account, and the other with the customer's purchase. Just like this.
100 1000.00
101 2000.00
102 3000.00
103 4000.00
the above is the balance.txt with customer nos (100 to 103) and their balances ( 1000 to 4000)
and the purchase.txt will look like below.
100 0000.00
101 0000.00
102 0000.00
103 0000.00
int main ()
{int key;
double balance, purchse;
cout<<" 4 Customer Account Types \n-*-*-*-*-*-*-*-*-\n 100, 101, 102, 103\n " ;
do{
cout<<" \nEnter one of the account numbers above : ";
cin>>key;
if (((key-100)<=3) && ((key-100) >= 0))
byte = (((key%100) * 18 ) + 10) ; // this is for seekg(byte) function to seek the value of balance from balance.txt
else {cout<<"Invalid Entry, Please Try again! \n"; }
}while (!((key-100)<=3 && (key-100) >= 0));
inFile.open("balance.txt"); // balance.txt is opened and seek the balance for coresponding customer
inFile.seekg(byte);
inFile >> balance;
cout<< "The balance is "<<balance<<endl;
inFile.close();
cout<< "Enter purchase value :"; // this is asking the user to enter the purchase amount
cin>>purchase;
if (purchase<balance || purchase == balance) // checking whether the balance limit exceeds
{
(?????????)// ******* if the purchase is approved i want to seek the byte corresponds to each customer and overwrite the purchase in purchse.txt
if i entered 1500 for purchase amount for account 101then it will show like this in purchase.txt and the others' will be still 0000.00
100 0000.00
101 1500.00
102 0000.00
103 0000.00
The same problem for the balance.txt file I want to sustract the purchase value from original balance value and Put back the new balance value in balance.txt file only for coresponding customer account without touching other account nos.
cout<< "Purchase Approved"<<endl ;
}
else cout<< "!!!!!! Purchase Exceeds the limit !!!!!"<<endl;
}
}
My Question is in red inside the program.
i don't know how to overwrite only one value and the other values remains unchanged.
One of my fascillitator said that I can use array to store all the values inside the text file and change whichever I want to change. Then put them back to txt file.
Looking forward to your solution.
If my question is not clear to you, feel free to ask me back.
Thank you in advance .;)
Uthnim