Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7.  
  8. {
  9.    
  10.     srand(static_cast<unsigned int>(time(0)));
  11.  
  12.     int count=1;
  13.    
  14.     int num =rand()% 10+1;
  15.    
  16.     int guess;
  17.    
  18.     char answer;
  19.    
  20.     int n;
  21.    
  22.     do
  23.     {
  24.     cout << "guess a number between 1 & 10" << endl;
  25.     cin >> guess;
  26.    
  27.     while (guess != num)
  28.     {
  29.         count++;
  30.        
  31.         cout <<"guess a number between 1 & 10 " << endl;
  32.         cin >> guess;
  33.        
  34.     }
  35.         cout << "It took " << count << " guesses to guess correctly" <<endl;
  36.         cout << " would you like to play again (y/n) " << endl;
  37.         cin >> answer;
  38.    
  39.     }
  40.     while (answer != n );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement