Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user1 pass1 55
- user2 pass2 56
- user3 pass3 57
- user1 pass1 55
- user2 pass2 44
- user3 pass3 57
- #include <iostream>
- #include <fstream>
- using namespace std;
- //function prototypes
- void addUser();
- int main();
- //global variables
- string username;
- string password;
- int balance;
- void addUser(){
- //open a file in write mode
- ofstream myfile;
- myfile.open("userinfo.txt", ios::app);//append the text file
- if(myfile.is_open()){
- cout<<"Please Create a Username: ";
- string inputCheck;//a string to compare name
- cin>>inputCheck;
- cout<<"Please Create a Password: ";
- cin>>password;
- cout<<"Current Balance: ";
- cin>>balance;
- myfile<<inputCheck<<' '<<password<<' '<<balance<<"n";
- myfile.close();
- cout<<"User account '"<<inputCheck<<"' has been created"<<endl;
- }//ends create a password else
- //ends if userCheck is open
- main();
- }
- int main()
- {
- cout<<"1.Add Usern2.Edit Information"<<endl;
- int input;
- cin>>input;
- if(input == 1){
- addUser();
- }else if(input == 2){
- //find the user
- cout<<"Enter the username: ";
- string checkUser;
- //string checkUser;
- cin>>checkUser;
- ifstream user;
- user.open("userinfo.txt");//open the file to be read in
- if(user.is_open()){//find the user
- bool foundUser = false;
- while(user>>username>>password>>balance){
- if(checkUser==username){
- foundUser = true;
- cout<<"User: "<<checkUser<<" Pass: "<<password<<" has been logged in"<<endl;
- break;
- }
- }
- if(foundUser){
- //while(infile>>username>>password>>balance);
- cout<<"Current Balance: "<<balance<<endl;
- cout<<"Enter new balance: ";
- cin>>balance;
- ifstream editBalance;//read from file to find user;
- //Here is where I am lost
- //get the new balance from the user
- //re-write the entire text file with the updated user balance
- //close the file
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement