Wrong values during a Do-While loop C++ -
i'm having trouble during do-while loop on code. it's interface class makes validation values typed user. i'm using visual studio 2012.
int interface::requestoption(){ int option; //el problema está aquí do{ cout<<"--------------------------------"<<endl; cout<<"type option..."; cin>>option; if(option<1 || option>8){ cout<<"invalid value, type again "<<endl; sleep(2000); system("cls"); menu(); } }while(!(option>0 && option<9)); return option;
}
if use method first time, returns value typed. when call again, while debug, notice value of option -893453, , also, doesn't allow me type number (cin >> option not working).
the method being called interact within next method:
void control::studentscontrol(){ int op; do{ system("cls"); interest->menu(); op = interest->requestoption(); lista<students>* students= null; students = u->getstudents(); switch(op){ //eight options //the 8th option return previous menu. }while(op != 8);
}
call std::cin.clear()
after each iteration before enter new value.
Comments
Post a Comment