So my problem goes like this:
string something (string something){
string letter;
cout << "press a";
cin >> letter;
if (letter==a){
return a;
}
else
cout << "wrong letter";
//what should I put here if I don't want it to return any value?
}
Any alternatives would also be welcome
>Solution :
Consider using the exception mechanism for this: this carries the advantage that you can keep a reasonable return type, and you can also delegate handling of the exception to the caller of the function.
First, write
struct WrongLetterException : public std::exception{};
Then change the function to
std::string something (std::string something/*ToDo - is this correct?*/){
std::string letter;
std::cout << "press a";
std::cin >> letter;
if (letter == 'a'/*note the change here*/){
return a;
}
throw WrongLetterException();
}
In the caller to the function, you then catch (const WrongLetterException& ex) and deal with it as you see fit.