I'm writing a program that has a large section of code with a lot of user input of different types. For example
1 2 3 4 5 6 7 8 9 10
cout<<"Please enter student name: "<<endl;
getline(cin,name); //read in string
cin.ignore()
cin.clear()
cout<<"Please enter student ID: "<<endl;
getline(cin,ID); //read in int
cin.ignore()
cin.clear()
//etc.. etc..
This user input goes on for about 8-10 more questions. I'm looking for the most efficient way to check that the user and input the correct type of data, and if they haven't prompt them to do so. Do you have any suggestions on how to do this? I know I could enter if statements after ever read in but this will end up looking rather messy!! I've tried messing around with template functions and stuff but I just get stuck.