Advertisement
ivanwidyan

Guess Number Between 1 - 100, Program Prints Too High or Low

Oct 19th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <ctime>
  2. #include <cstdlib>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int randRange(int, int);
  7.  
  8. int main() {
  9.     int HiddenNumber = 0;
  10.     int Input = 0;
  11.     srand(time(NULL));
  12.     HiddenNumber = randRange(1, 101);
  13.     cout << HiddenNumber << endl;
  14.     while (Input != HiddenNumber)
  15.     {
  16.         cout << "Can you guess what's the hidden number (1 - 100): ";
  17.         cin >> Input;
  18.         if (Input > HiddenNumber) {
  19.             cout << "Your guess number is too high" << endl;
  20.         }
  21.         else if (Input < HiddenNumber) {
  22.             cout << "Your guess number is too low" << endl;
  23.         }
  24.     }
  25.     cout << "Your answer is correct!" << endl;
  26. }
  27.  
  28. int randRange(int low, int high) {
  29.     return rand() % (high - low) + low;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement