Hello everyone so I came out with this piece of code while doing the challenge and I wonder why is it so different but it gives me same results.
Also I figured out I don’t need to output the boolean response in the main method as Ben did with his method since I get the return 1 (true) or 0 (false) automatically. I came up with this very naturally using my logic and I was actually surprised it worked maybe even better? I’m a complete newbie in coding and I’m afraid the way I wrote this code hides some potential issues.Here’s the two codes for comparison:
My code :
bool AskToPlayAgain()
{
cout << “Do you want to play again?”;
string Response = “”;
getline(cin, Response);
cout << "Is it y? " << (Response[0] == ‘y’ || Response[0] == ‘Y’);
cout << endl;
return false;
}
Ben’s code :
bool AskToPlayAgain()
{
cout << “Do you want to play again?”;
string Response = “”;
getline(cin, Response);
return (Response[0] == ‘y’) || (Response[0] == ‘Y’);
}
For the next lesson where you must return the boolean in order for the ‘do’ ‘while’ to work out i put the following : return (Response[0] == ‘y’ || Response[0] == ‘Y’);
instead of Ben’s : return (Response[0] == ‘y’) || (Response[0] == ‘Y’);
It’s still working right. so basically the only difference is that Ben’s is closing the “)” then asking OR with “||” while I’m not. What’s the difference?