update โปรเเกรมรายรับรายจ่าย +คำถามเพิ่ม pls help

ตอนนี้สามารถสร้าง infinite menu ด้วย do while เเละเพิ่มระบบ login กับ cout วันเวลา ปัจจุบัน เเต่ติดปัญหาคือ ผมอยากจะ writefile วันเวลา ปัจจุบัน เก็บลง bankmenu.txt ด้วย เเต่ไม่สามารถทำได้ ได้ลองใช้ตัวเเปรเดียวกับที่ cout เวลา ออกมา ในการ writefile มันก็ไม่ขึ้นใน .txt ช่วยเเนะนำด้วยครับ ขอบคุณทุกท่านไว้ล่วงหน้าครับ
พาพันขอบคุณพาพันขอบคุณ

#include<iostream>
#include<string>
#include<fstream>
#include<ctime>
using namespace std;
void line();
void log();
void time();
void time(){
  time_t now;
  struct tm nowLocal;
  now=time(NULL);
  nowLocal=*localtime(&now);
  cout<<"Today is : "<<nowLocal.tm_mday<<"/"<<" "<<nowLocal.tm_mon+1<<"/"<<" "<<nowLocal.tm_year+1900<<endl;
  cout<<"Time : "<<nowLocal.tm_hour<<"."<<" "<<nowLocal.tm_min<<"."<<" "<<nowLocal.tm_sec<<endl;
  

}

class loginmanager{
  public:
    string usernameattempt;
    string passwordattempt;
    loginmanager(){
      accessgranted=0;
    }
    void login(){
      
  
      cout<<"Please enter your password and username\nUsername :";
      cin>>usernameattempt;
      if(usernameattempt==username)
      {
        cout<<"Password :";
        cin>>passwordattempt;
        if(passwordattempt==password){
          
          cout<<"Welcome to ricefiled motherer\n";
    
        }
        else if(passwordattempt!=password) 
        {
        cout<<"password is not correct\n";
        system;exit (0);
        }
      }
      else if(usernameattempt!=username){
        cout<<"username is not correct\n";
        login();
  
      }
          }
          
    private:
    string username="xxxxx";
    string password="xxxxx";
    bool accessgranted;
  
};
void log()
{
loginmanager loginmanagerObj;
loginmanagerObj.login();
}
int main()
{
  
  time();
  log();
  
  int option;
  float currentmoney ,deposit,withdraw;
  string name ,linee;
  
  ofstream writefile;
  ifstream readfile;
  cout<<"Old input"<<endl;
  readfile.open("bankmenu.txt");
  while(getline(readfile,linee))
  {
    cout<<linee<<'\n';
    
  }
  readfile.close();
  
  writefile.open("bankmenu.txt",ios::app);
  line();
  cout<<"          HELLO ER"<<endl;
  cout<<"Please enter your name mother er :";
  cin>>name;
  
  cout<<"Please enter date and time you use this program "<<endl;
  
  writefile<<"Name :"<<name<<endl;
  
  cout<<"Welcome to money saving program Mr.:"<<name<<endl;
  cout<<"First add your current money :";
  cin>>currentmoney;
  
  do{
  
  cout<<"Please select option you want"<<endl;
  cout<<"1.Check your current money"<<endl;
  cout<<"2.Deposit your money"<<endl;
  cout<<"3.withdraw your money"<<endl;
  cout<<"4.Exit the program"<<endl;
  line();
  cout<<"Enter your option :";
  cin>>option;
  
    switch(option)
    {
      case 1:
        cout<<"Your current money is :"<<currentmoney<<endl;
        writefile<<"Checking money"<<endl;
        writefile<<"\t\t\tCurrent money :"<<currentmoney<<endl;
            
      break;
      case 2:
        cout<<"Amount money you want to deposit :";
        cin>>deposit;
        currentmoney = currentmoney+deposit;
        cout<<"Your current money after deposit is :"<<currentmoney<<endl;
        writefile<<"Deposit money :"<<deposit<<endl;
        writefile<<"\t\t\tCurrent money :"<<currentmoney<<endl;
        
      break;
      case 3:
        cout<<"Amout money you want to withdraw :";
        cin>>withdraw;
        currentmoney = currentmoney-withdraw;
        cout<<"Your current money after withdraw is :"<<currentmoney<<endl;
        writefile<<"Withdraw money :"<<withdraw<<endl;
        writefile<<"\t\t\tCurrent money :"<<currentmoney<<endl;
        
        break;
      case 4:
        cout<<"Program Close"<<endl;
        
        
        cout<<"Current money :"<<currentmoney<<endl;
        writefile<<"Close program"<<endl<<endl;
        system;exit (0);
        
    }
  }while(option!=0);
  
  
  return 0;
}

void line()
{
  cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
}
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่