The problem is that after entering the correct value (figures), it is not proposed to enter another value - size2. How to fix?

#include "stdafx.h" #include <iostream> #include <conio.h> #include "MyClass.h" using namespace std; int main() { MyClass a,b; int size1, size2; cout<<"Enter first size : "; while (!(cin >> size1) || (cin.peek() != '\n')) { cin.clear(); while (cin.get() != '\n'); cout << "nepravilno"; } cin>>size1; cout<<endl<<"Enter second size : "; cin>>size2; cout<<endl; a.set_mass(size1); b.set_mass(size2); a.show_mass(); cout<<endl; b.show_mass(); cout<<endl<<" intersection rezult : "<<endl; a.intersection(b); getch(); return 0; } 
  • Somehow I don’t see your input validation, except for the '\ n' character ... - Vladimir Martyanov

1 answer 1

See:

 while (!(cin >> size1) || (cin.peek() != '\n')) { cin.clear(); while (cin.get() != '\n'); cout << "nepravilno"; } cin>>size1; 

In the first line (inside the while ) you already considered size1 . After that, you fly into his reading a second time - in

 cin>>size1; 

and it is clear that before the withdrawal of the invitation to enter the second number it does not reach ...