0

What is another way to rewrite this? This function is called when the user says their number is higher in the program

virtual void higher() {
   //dont go above high
low = (getCurrentGuess() + 1 > high) ? high : getCurrentGuess() + 1;
seed = time(NULL);
}
  • it is an if statement. `a = b ? c : d` means `if (b) a=c; else a=d;` It is called the ternary operator. Here are three pages that might help: https://www.w3schools.com/cpp/cpp_conditions_shorthand.asp https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/ https://www.tutorialspoint.com/c-cplusplus-ternary-operator An example it is useful for is `bool x=false; printf("%s",x?"true":"false");` – Jerry Jeremiah Dec 07 '20 at 04:34
  • This is called a ternary operator. You can simply use an if-else operation. But it does the same. – Chamin Wickramarathna Dec 07 '20 at 04:35

0 Answers0