SHARE
TWEET

Untitled

a guest Dec 6th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. user1 pass1 55
  2.  
  3. user2 pass2 56
  4.  
  5. user3 pass3 57
  6.    
  7. user1 pass1 55
  8.  
  9. user2 pass2 44
  10.  
  11. user3 pass3 57
  12.    
  13. #include <iostream>
  14. #include <fstream>
  15.  
  16. using namespace std;
  17. //function prototypes
  18. void addUser();
  19. int main();
  20.  
  21. //global variables
  22.     string username;
  23.     string password;
  24.     int balance;
  25. void addUser(){
  26.     //open a file in write mode
  27.         ofstream myfile;
  28.         myfile.open("userinfo.txt", ios::app);//append the text file
  29.         if(myfile.is_open()){
  30.         cout<<"Please Create a Username: ";
  31.         string inputCheck;//a string to compare name
  32.         cin>>inputCheck;
  33.         cout<<"Please Create a Password: ";
  34.         cin>>password;
  35.         cout<<"Current Balance: ";
  36.         cin>>balance;
  37.         myfile<<inputCheck<<' '<<password<<' '<<balance<<"n";
  38.         myfile.close();
  39.         cout<<"User account '"<<inputCheck<<"' has been created"<<endl;
  40.         }//ends create a password else
  41.         //ends if userCheck is open
  42.     main();
  43. }
  44. int main()
  45. {
  46.     cout<<"1.Add Usern2.Edit Information"<<endl;
  47.     int input;
  48.     cin>>input;
  49.     if(input == 1){
  50.         addUser();
  51.     }else if(input == 2){
  52.     //find the user
  53.     cout<<"Enter the username: ";
  54.     string checkUser;
  55.     //string checkUser;
  56.     cin>>checkUser;
  57.     ifstream user;
  58.     user.open("userinfo.txt");//open the file to be read in
  59.     if(user.is_open()){//find the user
  60.     bool foundUser = false;
  61.     while(user>>username>>password>>balance){
  62.         if(checkUser==username){
  63.         foundUser = true;
  64.         cout<<"User: "<<checkUser<<" Pass: "<<password<<" has been logged in"<<endl;
  65.         break;
  66.         }
  67.     }
  68.     if(foundUser){
  69.     //while(infile>>username>>password>>balance);
  70.     cout<<"Current Balance: "<<balance<<endl;
  71.     cout<<"Enter new balance: ";
  72.     cin>>balance;
  73.     ifstream editBalance;//read from file to find user;
  74.     //Here is where I am lost
  75.     //get the new balance from the user
  76.     //re-write the entire text file with the updated user balance
  77.     //close the file
  78.     }
  79.     }
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top