Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <windows.h>
  4. #include <string>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. int num, numrand;
  12. char in;
  13. srand(time(NULL));
  14. string name;
  15. cout << "Welcome to my program, please enter your name " << name << endl;
  16. cin >> name;
  17. cout << "Hi " << name << " do you want to play a game? i/n" << endl;
  18. cin >> in;
  19. if (in == 'n' || in == 'N')
  20. return 0;
  21. while (true)
  22. {
  23. cout << "The PC is thinking to a number from 0 to 5, and you need to guess it " << endl;
  24. cin >> num;
  25. numrand = rand() % 6;
  26. if (numrand == num)
  27. {
  28. cout << "Congrats, you win :-)" << endl;
  29. break;
  30. }
  31. else if (num <= -1)
  32. break;
  33. while (num != numrand)
  34. {
  35. if (num < numrand)
  36. {
  37. cout << "You were wrong, the number is smaller than: " <<num<<endl;
  38. break;
  39.  
  40. }
  41. if (num > numrand)
  42. {
  43. cout << "You were wrong, the number is greater than: " <<num<< endl;
  44. break;
  45.  
  46. }
  47. }
  48. }
  49.  
  50.  
  51. system("pause");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement