Hey, im new to c++. I had to make a unit converter to class. Im trying to add validation as a little extra challenge, but im having an issue. If i type in a correct unit validated with regex, my code will go on and run like normal. However, if it doesnt pass, it will ask for input again, however it does not complete the calculations properly. My feeling is that it has something to do with my stringstream, input getting caught up? i worked with .clear and .ignore and had no luck.
int main(){
// Output a title, ask the user to enter the mass that will be calculated
cout << "Mass converter, (c)2017: " << endl;
cout << "Enter the mass: ";
getline(cin, input);
while (!regex_match(initialUnit, reg_unit))
{
cout << mass << " " << initialUnit << " is an unknown unit and cannot be converted." << endl;
cout << "Enter a valid mass: (ex. lb, g, dwt, etc.)";
getline(cin, input);