// Problem 2


class Account {


private:


   string id = "Unknown";

   int balance = 0, last_day = 0;

   double annual_rate = 0;


public:


   Account() {}

   Account(string id, int balance, double annual_rate, int last_day) {

      this->id = id;

      this->balance = balance;

      this->annual_rate = annual_rate;

      this->last_day = last_day;


      cout << "계좌명: " << id << "   연 이자율: " << annual_rate << '%' << endl

         << "날짜" << "   예금액" << "   출금액" << "   이자" << "   잔액" << endl;

   }

   int getDuration(int now) {

      int d = 0;

      d = now - last_day; // d는 경과 날짜

      if (d < 0)

         cout << "현 시점 날짜 입력 잘못!!!" << endl;


      last_day = now;


      return d;

   }

   int getInterest(int d) {

      int interest = 0;

      interest = annual_rate / 36500 * d * balance; // interest는 이자

      return interest;

   }

   void withdraw(int amount, int d) {

      if (d >= 0) {

         balance += getInterest(d);

         if (amount > balance)

            cout << "잔액이 모자랍니다." << endl;

         else {

            balance -= amount;

         }

      }

   }

   void deposit(int amount, int d) {

      if (d >= 0) {

         balance += getInterest(d);

         balance += amount;

      }

   }

   void cancel(int d) {

      if (d >= 0) {

         balance += getInterest(d);

         cout << endl << "정산할 금액 : " << balance << endl

            << "그 동안 거래에 감사드립니다." << endl;

      }

   }

   void print(int now, int dep, int wit) {

      if (dep > 0)

         deposit(dep, getDuration(now));

      else if (wit > 0)

         withdraw(wit, getDuration(now));

      else

         deposit(dep, getDuration(now)); // 입출금 모두 없는 경우, 경과 날짜에 따른 이자를 받기 위해


      cout << now << "   " << dep << "   " << wit << "   " << getInterest(getDuration(now)) << "   " << balance << endl;

   }

};



int main() {

   // Problem 2


   Account* ac = new Account("김철수", 20000, 5, 15);

   ac->print(15, 0, 0);

   ac->print(60, 0, 2500);

   ac->print(80, 0, 19000);

   ac->print(90, 3000, 0);

   ac->print(120, 0, 0);

   ac->cancel(ac->getDuration(120));

}


-----


c++ 이구연


아래 사진(흰 사진)처럼 나와야하는데 위 사진(검은 사진)처럼 나옵니다.






지금 다 잘 나오는데 print 함수에서 이자에 해당하는 getInterest(getDuration(now)) 이 죄다 0으로 출력되그등요?


이거 도당체 왜이러는 지 좀 알려주세요 어떻게 바꾸면 이자를 출력할 수 있을까요?


전체 함수들끼리 상호작용은 잘 돼서 잔액은 제대로 나오는데 출력할 때만 0으로 나와요!!! 이거 왜 이럼 도대체!!!!!!