2014-11-05 4 views
-4

나는 주식 거래 프로그램을 프로그래밍하고하지 않고 파일 편집. 이 기능의 경우 특정 계정의 잔액을 변경해야하지만 파일로 다시 출력 할 때마다 한 계정의 잔액을 업데이트하고 다른 사용자는 모두 삭제합니다.C++ deleting.other 정보

소스 코드 : 그래서 그것은 단지 자신의 ID를 사용하여 로그인하는 사람의 계정 잔액을 변경 내가 편집해야하지만, 내가 무엇을해야하는지에 절대적으로 우둔 어딘지

void Buying() 
{ 
    ifstream Companies; 
    ifstream Account; 
    Account.open("Account.txt"); 
    { 
     int ID; 
     double cash; 
     string sym; 
     ifstream Account; 
     Account.open("Account.txt"); 
     //Check for errord 
     if (Account.fail()) 
     { 
      cout << "Failed" << endl; 
      exit(1); 
     } 
     account S_accounts; 
     for (int i = 0; i < 5; i++) 
     { 
      Account >> S_accounts.id[i] >> S_accounts.cash[i]; 

     } 
     cout << "Please enter your last 4 digits of your ID: "; 
     do 
     { 
      cin >> ID; 
      cout << endl; 
      switch (ID) 
      { 
      case 1111: 
       cash = S_accounts.cash[0]; 
       break; 
      case 2222: 
       cash = S_accounts.cash[1]; 
       break; 
      case 3333: 
       cash = S_accounts.cash[2]; 
       break; 
      case 4444: 
       cash = S_accounts.cash[3]; 
       break; 
      case 5555: 
       cash = S_accounts.cash[4]; 
       break; 
      default: 
       cout << "ID number is invalid. please try again." << endl; 
      } 
      break; 
     } while (ID != 1111 || ID != 2222 || ID != 3333 || ID != 4444 || ID != 5555); 
     if (cash > 36.80) 
     { 
      cout << "You have $" << cash << " what stock would you like to purchase?" << endl; 
      listing(); 
      cout << endl; 
      cout << "Type the stock symbol of the company that you would like to purchase." << endl; 
      cin >> sym; 
      double price; 
      int number_of_stock; 
      double total; 
      int i = 0; 
      while (i < 7) 
      { 
       Stock S_companies; 
       Companies >> S_companies.price[i]; 
       i++; 
      } 
      //Stock S_companies; 
      if (sym == "AAPL" || sym== "aapl") 
      { 
       price = 450.00; 
      } 
      else if (sym == "BA" || sym == "ba") 
      { 
       price = 75.50; 
      } 
      else if (sym == "INTC" || sym == "intc") 
      { 
       price = 22.30; 
      } 
      else if (sym == "RMBS" || sym == "rmbs") 
      { 
       price = 5.55; 
      } 
      if (sym == "SIRI" || sym == "siri") 
      { 
       price = 3.15; 
      } 
      if (sym == "SWKS" || sym == "swks") 
      { 
       price = 25.35; 
      } 
      if (sym == "XLNX" || sym == "xlnx") 
      { 
       price = 36.80; 
      } 
      cout << "How many stock(s) would you like to buy?" << endl; 
      cin >> number_of_stock; 
      total = number_of_stock*price; 
      if (cash > total) 
      { 
       account S_account; 
       ofstream Oaccount; 
       Oaccount.open("Account.txt"); 
       if (Oaccount.fail()) 
       { 
        "Failed to open the file."; 
       } 

나는 이것을 알고있다.

   if (ID == 1111) 
       { 
         Oaccount << S_accounts.id[0] << '\t' << '\t' << S_accounts.cash[0] - total; 
       } 
       Oaccount.close(); 
      } 
      else 
       cout << "You do not have enough money."; 
     } 
     else 
     { 
      cout << "Sorry, you do not have enough money in your account."; 
      exit(1); 
     } 
     Account.close(); 
    } 
} 

답변

0

임은 code.But을 이렇게하면/업데이트 항목을 수정하는 방법입니다 디버깅하지 ... 하자 번호는 ... 당신이 자신을 변경하려면 말할 수 계정을 찾으려과 값 새 이름으로 이름 ...

while(!file.eof()) 
{ 
    if(obj.number==given_value) 
    { 
     file.tellg(pos); 
     { 
      //modify values here like.. 
      strcpy(obj.name,newname); 
      file.seekg(pos); 
      file.write((char*)&obj,sizeof(obj)); 
     } 
    } 
} 
+0

이 질문에 답할 수 없습니다. – cybermonkey