Advertisement
DrDiagramm

Untitled

Feb 9th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 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. int passed=0;
  12.  
  13. std::cout << "Guessing Game! Try guessing the Number, from 1-9000\n\n";
  14.  
  15. int ranNum = randNumb();
  16. std::cout << "Guess the Number now! ";
  17.  
  18. do{
  19. while (passed!=1) {
  20.  
  21. int guNum = guess();
  22. if (guNum == ranNum) {
  23. std::cout << "Yes! Thats right!!!\n\n";
  24. int passed = 1;
  25.  
  26. }
  27.  
  28. else {
  29. if (guNum > ranNum) {
  30. std::cout << "The guessed number is bigger than the wanted number.\n";
  31.  
  32. }
  33. else {
  34. std::cout << "The guessed number is smaller than the wanted number.\n";
  35. }
  36. }
  37. }
  38. std::cout << "do you want to do it again?\n";
  39. std::cin >> question;
  40. if (question == "yes") {
  41. int x = 0;
  42. int ranNum = randNumb();
  43. std::cout << "Guess the Number now! ";
  44. }
  45. }while (question == "yes");
  46. system("pause");
  47. return 0;
  48. }
  49. int randNumb() {
  50. int i = 1 + (rand() % 9);
  51. return i;
  52.  
  53.  
  54. }
  55. int guess() {
  56. int j;
  57. std::cin >> j;
  58. return j;
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement