fork download
  1. #include <iostream>
  2.  
  3. // main() can also be declared without arguments.
  4. // Its arguments, if specified, are used by the OS to send command line parameters to the program.
  5. int main() {
  6. int numberOfPlayers = -1; // Invalid value, used for flag.
  7.  
  8. do {
  9. std::cin >> numberOfPlayers;
  10.  
  11. if (numberOfPlayers < 2 || numberOfPlayers > 4) {
  12. std::cout << "That's impossible! Don't mock me!\n";
  13. numberOfPlayers = -1;
  14. }
  15. } while (numberOfPlayers == -1);
  16. std::cout << "Great!" << std::endl;
  17. }
Success #stdin #stdout 0s 15240KB
stdin
1
5
9
-6
3
stdout
That's impossible!  Don't mock me!
That's impossible!  Don't mock me!
That's impossible!  Don't mock me!
That's impossible!  Don't mock me!
Great!