سورس برنامه حدس عدد تصادفی کامپیوتر توسط کاربر

#include"iostream.h"
#include"conio.h"
#include"stdlib.h"

const int totchan=7;
void main(){
 int number;
 int guess;
 int chances=0,score=0,chanscor;

 char ans;
 do{  

clrscr();
   chances=score=0;
 cout<<"Welcome to the High/Low game.";
 cout<<"I will pick a random number from 0 to 100.";
 cout<<"You must try to guess the number.";
   randomize();
   number=(int)(rand()%100);
 chanscor=100/totchan;
   do{
   cout<<"What is your guess? (0 to 100) \n\n";
     cin>>guess;
     if((guess<0)||(guess>100)){
 cout<<"Sorry, but your guess "<<guess<<"must be from 0 to 100.";
     }
     else if(guess < number){
 cout<<guess<<" is low.Try a higher number.\n";
   }
   else if(guess > number){
 cout<<guess<<" is high.Try a lower number.\n";
     }
   else{
 cout<<guess<<" is correct. Congratulations!";
 score=chanscor*(totchan-chances);

 cout<<"Your score is "<<score<<endl;
        break;
     }
     chances++;
     if(guess!=number)
  cout<<"Now you have "<<totchan-chances<<"chances left."<<endl;
   if(chances==totchan){
   cout<<"Only "<<totchan<<"chances are allowed.Better luck nexttime";
   cout<<"The actual number was "<<number<<endl;
    break;
  }
     }while (guess!=number);
   cout<<"Thank you for playing High/Low!";
     cout<<"Want to play it again? (y/n)...";
     cin>>ans;
   }while(ans=='y' || ans=='Y');
 }

نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد