title: Having confusion with if ledder containg array in C++
body: <pre><code>#include&lt;iostream&gt;
  #include&lt;conio.h&gt;
  
  using namespace std;
  //const int n=20;
  
  class cofee
  {     
     //public:
     int i;
     //int n=20;
     int price[20];
     //int totalprice[n];
  
     public:
     void getprice()
     {    
        if(i=1)
        {
           price[i]=10;
           cout&lt;&lt;"price is :"&lt;&lt;price[i]&lt;&lt;""\n;
        }
        else if(i=2)
        {
           price[i]=20;
           cout&lt;&lt;"price is :"&lt;&lt;price[i];
        }
        else if(i=2)
        {
           price[i]=30;
           cout&lt;&lt;"price is :"&lt;&lt;price[i];
        }
        else
        {
           cout&lt;&lt;"\n";
        }
     }
  
     void total()
     {
        int sum=0;
        int n=3;
        for(i=1;i&lt;=n;i++)
        {
           sum = sum+price[i];
        }
        cout&lt;&lt;"total is:"&lt;&lt;sum;
     }
  };
  
  int main()
  {
     cofee c;
     int i;
  
     do
     {
        cout&lt;&lt;"enter your choice";
        cout&lt;&lt;"\n1.plain cofee";
        cout&lt;&lt;"\n2.cold cofee";
        cout&lt;&lt;"\n3.farali cofee";
        cout&lt;&lt;"\n4.total";
        cout&lt;&lt;"\n5.quit";
        cout&lt;&lt;"\n";
        cin&gt;&gt;i;
  
        switch(i)
        {
           case 1 : c.getprice(); break;
           case 2 : c.getprice(); break;
           case 3 : c.getprice(); break;
           case 4 : c.total(); break;
           case 5 : break;
           default : cout&lt;&lt;"\nwrong cchoice";
        }
     }while(i!=5);
  
     getch();
     return 0;
  }
  </code></pre>
  
  <p>i have tried almost everything i could but still its not giving proper output. neither its showing any error or warning.</p>
  
  <p>in if else ledder price is not storing value for i=2 &amp; 3. need help to solve it.</p>