Iteration of loop

This is a discussion on Iteration of loop within the C++ Programming forums, part of the General Programming Boards category; Hello All, Here is the programm simulating the ATM. I want the little help in how to repeat the conditions ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    6

    Iteration of loop

    Hello All,

    Here is the programm simulating the ATM.

    I want the little help in how to repeat the conditions in loop, because as I change the conditions, program doesn't perform any calculation.

    Kindly if anybody can help me in this regard.

    Code:
    #include<iostream.h>
    #include<string.h>
    #include<iomanip.h>
    #include<conio.h>
    
    class BankTransaction
    
     {
        private:
    	int iBalance,NewBalance,Adjustment,AnnualInterestRate,Interest;
        public:
    	void Deposit();
    	void Withdrawl();
    	void Balance();
    	void Display();
    	void InterestRate();
    	void AnnualInterest();
     };
    
     void BankTransaction :: Deposit ()
    
    
    	{
    		cout<<"\n Enter the amount to deposit:";
    		cin>>NewBalance;
    		iBalance = iBalance + NewBalance;
    
    	}
    
     void BankTransaction :: Withdrawl()
    
    
    	{
    
    		int amount = 0;
    		cout<<"Enter amount to be withdraw:\n";
    		cin>>amount;
    
    		if(amount >iBalance)
    
    		{
    			cout<<"Not enough balance to be withdrawn.\n";;
    			cout<<"Maximum money can be withdrawn: "<<iBalance<<"\n";
    		}
    		else
    		{
    
    		  iBalance = iBalance - amount;
    		}
    
    	}
    
     void BankTransaction :: Balance()
    
    
    	{
    	       cout<<"Current Balnce: " <<iBalance;
    	}
    
    void BankTransaction:: InterestRate()
    
    
    	{
    		cout<<"\n Enter the interest rate: \n";
    		cin>>AnnualInterestRate;
    	}
    
    void BankTransaction:: AnnualInterest ()
    
    
    	{
    
    		cout<<"\n Enter the interest rate: \n";
    		iBalance = iBalance -(AnnualInterestRate / 100);
    		  cout<<"Current Balance: " << iBalance;
    
    
    	}
    
    
    void main()
    
    
    		{
    			BankTransaction  a; //creating array of objects
    			int input = 0;
    			do
    			{
    				clrscr();
    				cout<<"\n Enter the value to perform : \n";
    				cout<<"\n 1: Deposit : \n";
    				cout<<"\n 2: Withdraw : \n";
    				cout<<"\n 3: Get Balance : \n";
    				cout<<"\n 4: Set annual interest rate  : \n";
    				cout<<"\n 5: Calculate interest  : \n";
    
    
    				cin>>input ;
    
    				if(input == 1)
    				   a.Deposit();
    			       else if(input == 2)
    				   a.Withdrawl();
    			       else if(input == 3)
    				   a.Balance();
    			       else if(input == 4)
    				   a.InterestRate();
    			       else if(input == 5)
    				   a.AnnualInterest();
    
    			       //	 a.Display();
    
    
    			}while(input == 0);
    
        getch();
    
    }
    Regards

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Perhaps you meant to loop

    Code:
    while(input != 0);
    You'll see you have other problems, like having uninitialized member variables.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User n3cr0_l0rd's Avatar
    Join Date
    Feb 2009
    Posts
    62
    The loop will continue if the input is 0. But that would be useless because if the input is 0, you will just keep on looping without doing anything. If you meant to loop every time the input is not 0, do as anon said. Again that will lead you to never-ending loop unless you input 0.

    You have used clrscr() at the beginning of the loop so don't expect to see the results displayed by
    Code:
    a.AnnualInterest();
    as it will erase it.

    There's a big chance i didnt get u.. :d

    something that i have learned so far. Maybe you would like to know too. Don't use void main, instead use int main().
    The main function is required to yield an integer as its result, the purpose of which is to tell the
    implementation whether the program ran successfully. A zero value indicates success; any
    other value means there was a problem.

    conio.h is not standard header file for C++, ditch it; obviously getch() too goes with it.
    I had crush on her, before that crush could CRUSH me, i CRUSHED that crush !!! Fun time over, Lets find a way to not to blow off the whole leg !

    __________________________________________________ __________________________________________________ _______________

    In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg.
    - Bjarne Stroustrup

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  2. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  3. kernel iteration through for loop
    By sononix in forum C++ Programming
    Replies: 4
    Last Post: 08-11-2004, 06:16 AM
  4. Loop iteration v's vectors
    By sononix in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2004, 10:25 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21