title: cross initialization error in while loop (c++ program)
body: <p>I am doing a lot of things wrong here. Plz help.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  class student {
      int rno;
      char name[15];
      float marks;
  
  public:
      void getdata()
      {
          cout &lt;&lt; "\nEnter Roll No. : ";
          cin &gt;&gt; rno;
  
          cout &lt;&lt; "\nEnter Name : ";
          cin &gt;&gt; name;
  
          cout &lt;&lt; "\nEnter Marks : ";
          cin &gt;&gt; marks;
      };
  
      void writedata()
      {
          fstream input;
          input.open("stu.dat", ios::out | ios::app);
          input.write((char*)this, sizeof(student));
          input.close();
      };
  
      void readdata()
      {
          int temp;
          cout &lt;&lt; "\nEnter roll no: ";
          cin &gt;&gt; temp;
  
          fstream output;
          output.open("stu.dat", ios::in);
          output.seekg(0, ios::beg);
  
          while (output.read((char*)this, sizeof(student))) {
              if (rno == temp) {
                  cout &lt;&lt; "\nRoll no. : " &lt;&lt; rno
                       &lt;&lt; "\nName : " &lt;&lt; name
                       &lt;&lt; "\nMarks : " &lt;&lt; marks;
              }
              else {
                  cout &lt;&lt; "\nWrong Roll no entered";
              };
          };
      };
  };
  
  int main()
  {
      student s[25];
      student* st;
  
      char ans = 'y', ans2 = 'y', ans3 = 'y';
  
      int o, i = 0, j = 0;
  
      do {
          cout &lt;&lt; "\nEnter your choice\n1.Write\n2.Read";
          cin &gt;&gt; o;
  
          switch (o) {
          case 1:
              while (ans2 == 'y' || ans2 == 'Y') {    
                  s[i].getdata();
                  s[i].writedata();
  
                  cout &lt;&lt; "\nDo you want to continue?";    
                  cin &gt;&gt; ans2;
  
                  i++;
              };
              break;
          case 2:
              while (ans3 == 'y' || ans3 == 'Y') {
                  st-&gt;readdata();
                  cout &lt;&lt; "\nDo you want to continue?";
                  cin &gt;&gt; ans3;
  
                  j++;
              };
  
              break;
          };
      } while (ans == 'y' || ans == 'Y');
  
      return 0;
  }
  </code></pre>