fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7. int y, n;
  8. cout << "You are invited to play!!!" << endl;
  9. cout << "Pick a number" << endl;
  10. cin >> y;
  11.  
  12. if ((y % 3) == 2) {
  13. y = y - 2;
  14. cout << "I am subtracting 2" << endl;
  15. }
  16. else {
  17. y--;
  18. cout << "I am subtracting 1" << endl;
  19. }
  20.  
  21.  
  22. cout << "New total is " << y << endl;
  23. if (y == 0) {
  24. cout << " I WIN!" << endl;
  25. return 0;
  26. }
  27.  
  28. cout << "Enter a number to subtract (has to be either 1 or 2)" << endl;
  29. cin >> n;
  30. while (n < 1 || n>2) {
  31. cout << "Input must be 1 or 2" << endl;
  32. cout << "Re-enter" << endl;
  33. cin >> n;
  34. }
  35. y = y - n;
  36. cout << "The new total is " << y << endl;
  37. if (y == 0) {
  38. cout << "GG NO RE" << endl;
  39. cout << "Congrats, you beat me " << endl;
  40. return 0;
  41. }
  42.  
  43. system("PAUSE");
  44. return 0;
  45. }
Success #stdin #stdout #stderr 0s 15240KB
stdin
-1
-3
-4
5
2
stdout
You are invited to play!!!
Pick a number
I am subtracting 1
New total is -2
Enter a number to subtract (has to be either 1 or 2)
Input must be 1 or 2
Re-enter
Input must be 1 or 2
Re-enter
Input must be 1 or 2
Re-enter
The new total is -4
stderr
sh: 1: PAUSE: not found