fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9. int END = 0;
  10. int attempts = 0;
  11. string repeat;
  12.  
  13. while(END <= 0 || attempts > 3){
  14. int answer = rand()%21;
  15. int guess;
  16. int attempt;
  17.  
  18. cout << "I'm thinking of a number from 1 through 20.\n\n";
  19. cin >> guess;
  20. if(guess == answer){
  21. cout << "Congratulations, you've won!\n\n";
  22. END += 1;
  23. system("pause");
  24. }
  25. else{
  26. attempt += 1;
  27. cout << "That's not the right number, guess again.\n\n";
  28. }
  29. }
  30. {
  31. cout << "You've guessed wrong 3 times. The answer was " << answer << ".\n\n";
  32. cout << "Play again? [Y N]";
  33. if(repeat == "y"){
  34. END == 0;
  35. attempts == 0;
  36. repeat == "x";
  37. }
  38. else{
  39. cout << "Thanks for playing!\n\n";
  40. system("pause");
  41. }
  42. }
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from prog.cpp:2:
In file included from /usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/random:35:
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
 ^
prog.cpp:31:61: error: use of undeclared identifier 'answer'
        cout << "You've guessed wrong 3 times. The answer was " << answer << ".\n\n";
                                                                   ^
prog.cpp:34:7: warning: equality comparison result unused [-Wunused-comparison]
                END == 0;
                ~~~~^~~~
prog.cpp:34:7: note: use '=' to turn this equality comparison into an assignment
                END == 0;
                    ^~
                    =
prog.cpp:35:12: warning: equality comparison result unused [-Wunused-comparison]
                attempts == 0;
                ~~~~~~~~~^~~~
prog.cpp:35:12: note: use '=' to turn this equality comparison into an assignment
                attempts == 0;
                         ^~
                         =
prog.cpp:36:10: warning: equality comparison result unused [-Wunused-comparison]
                repeat == "x";
                ~~~~~~~^~~~~~
prog.cpp:36:10: note: use '=' to turn this equality comparison into an assignment
                repeat == "x";
                       ^~
                       =
3 warnings and 2 errors generated.
stdout
Standard output is empty