# Iteration of loop

• 06-11-2009
funky
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
• 06-11-2009
anon
Perhaps you meant to loop

Code:

`while(input != 0);`
You'll see you have other problems, like having uninitialized member variables.
• 06-11-2009
n3cr0_l0rd
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. :D