Hi
I'm playing with a simple class. Looks like everething is fine, my compiler doesn't give me any error but there is no display on the screen. Can anyone tell me what did I miss?
thanks

#include <iostream>
#include <conio.h>
using namespace std;
class BankAccount
{
  public:
         BankAccount(int dollar,int cent, double rate);
         //constructor that assigns dollar into a dollar of the amount
         //cent into cents of the amounts and the rate into interest rate
  
         BankAccount(int dollar, double rate);
         //contsructor that assigns a dollar into a dollar of the amount
         //cents into 0 and rate into interest rate
  
         BankAccount();
         //default constructor that assigns the dollar and cents into 0.0
         //and rate into 0;
         
         void check_input(int dollar,int cent,double rate);
         //the function that check if the input is correct
         
         void check_input(int dollar, double rate);
         
         void output(ostream& out);
         // The function that outputs the result either to file or screen
         
  private:
          double fraction(int cents);
          double get_balance();
          int dollars;
          int cents;
          double interest_rate;
};
 
int main()
{
  BankAccount account1(100,2,2.3),account2;  
  cout<<"Your account1 is initialized as fallows: ";
  account1.output(cout);   
  cout<<"Your account2 is initialized as fallows: ";
  account2.output(cout);
  //cout<<"Your account3 is initialized as fallows: ";
  //account2.output(cout);
  
  getch();
  return 0;
}
BankAccount::BankAccount(int dollar,int cent, double rate)
{
  check_input(dollar,cent,rate);
  dollars=dollar;
  cents=cent;
  interest_rate=rate;
  fraction(cents);
}
BankAccount::BankAccount(int dollar,double rate)
{
  check_input(dollar,rate);
  dollars=dollar;
  cents=0;
  interest_rate=rate;
}
BankAccount::BankAccount() : dollars(0),cents(0),interest_rate(0.0)
{
                           
}
void BankAccount::check_input(int dollar,int cent,double rate)
{
  if ((dollar<0)||(cent<0)||(rate<0))
    cout<<"Illigal values !!!";
    exit(1);
}
void BankAccount::output(ostream& out)
{ 
       
  out.setf(ios::fixed);
  out.setf(ios::showpoint);
  out.precision(2);   
  out<<"Account balance : ";
  out<<get_balance();
  out<<"\nInterest rate : ";
  out<<interest_rate;
}
double BankAccount::fraction(int cents)
{
  return (cents*0.01);
}
void BankAccount::check_input(int dollar,double rate)
{
  if ((dollar<0)||(rate<0))
    cout<<"Illigal values";
    exit(1);
}
double BankAccount::get_balance()
{
  return (dollars+(cents*0.01));
}

cout<<"Your account1 is initialized as fallows: ";
account1.output(cout);

That doesn't look right.

Are you trying to overload the << operator or something?

void BankAccount::check_input(int dollar,int cent,double rate)
{
  if ((dollar<0)||(cent<0)||(rate<0))
    cout<<"Illigal values !!!";
[B]    exit(1);[/B]
}

Look at this line, and where it is. (Ignore indentation) what happens in this function?

This article has been dead for over six months. Start a new discussion instead.