Guest User

Untitled

a guest
Jan 12th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. #include<cstdlib> //亂數所在的函式
  4.  
  5. int main(){
  6. int guess=0;
  7. int number;//rand
  8. char x='Y';
  9. int n;
  10.  
  11. cout<<"I have a number between 1 and 1000."<<endl;
  12. cout<<"Can you gusee my number?"<<endl;
  13. cout<<"Please type you first guess."<<endl;
  14.  
  15. number=1+rand()%1000;
  16.  
  17. while(x=='y' || x=='Y')
  18. {
  19. do
  20. {
  21. cout<<"?";
  22. cin>>guess;
  23. if(guess<number)
  24. cout<<"Too low!Try again!"<<endl;
  25.  
  26. if(guess>number)
  27. cout<<"Too high!Try again!"<<endl;
  28. }
  29. while(guess!=number);
  30. cout<<"Excellent!You guessed the number!"<<endl;
  31. cout<<"Would you like try again(y or n)?";
  32. cin>>x;
  33. }
Add Comment
Please, Sign In to add comment