Advertisement
DrDiagramm

Untitled

Feb 9th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <string>
  5. int guess();
  6. int randNumb();
  7. int main() {
  8. int guNum;
  9. std::string question;
  10. srand(time(0));
  11. bool passed = true;
  12. std::string again;
  13.  
  14. std::cout << "Guessing Game! Try guessing the Number, from 1-100\n\n";
  15.  
  16. int ranNum = randNumb();
  17.  
  18.  
  19.  
  20. while (passed) {
  21.  
  22. int guNum = guess();
  23. if (guNum == ranNum) {
  24. std::cout << "Yes! Thats right!!!\n\n";
  25. std::cout << "Want to do it again? yes or no.\n";
  26. std::cin >> again;
  27.  
  28. if (again == "yes") {
  29. int ranNum = randNumb();
  30. }
  31. else {
  32. passed = false;
  33. }
  34.  
  35.  
  36. }
  37.  
  38. else if (guNum > ranNum) {
  39. std::cout << "The guessed number is bigger than the wanted number.\n";
  40.  
  41. }
  42. else {
  43. std::cout << "The guessed number is smaller than the wanted number.\n";
  44. }
  45. }
  46.  
  47. system("pause");
  48. return 0;
  49. }
  50. int randNumb() {
  51. int i = 1 + (rand() % 9);
  52. std::cout << "Guess the Number now!\n";
  53. return i;
  54.  
  55.  
  56. }
  57. int guess() {
  58. int j;
  59. std::cin >> j;
  60. return j;
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement