Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #include<cstdlib> //亂數所在的函式
- int main(){
- int guess=0;
- int number;//rand
- char x='Y';
- int n;
- cout<<"I have a number between 1 and 1000."<<endl;
- cout<<"Can you gusee my number?"<<endl;
- cout<<"Please type you first guess."<<endl;
- number=1+rand()%1000;
- while(x=='y' || x=='Y')
- {
- do
- {
- cout<<"?";
- cin>>guess;
- if(guess<number)
- cout<<"Too low!Try again!"<<endl;
- if(guess>number)
- cout<<"Too high!Try again!"<<endl;
- }
- while(guess!=number);
- cout<<"Excellent!You guessed the number!"<<endl;
- cout<<"Would you like try again(y or n)?";
- cin>>x;
- }
Add Comment
Please, Sign In to add comment